unusual c# - oop

29
Unusual C# OOP Gate Prepared & Presented by: Eng. : Medhat Dawoud

Upload: medhat-dawoud

Post on 19-May-2015

1.253 views

Category:

Technology


1 download

DESCRIPTION

session @ ITzo0M4 2010

TRANSCRIPT

Page 1: Unusual C# - OOP

Unusual C#OOP Gate

Prepared & Presented by:Eng. : Medhat Dawoud

Page 2: Unusual C# - OOP

Relax your self

Page 3: Unusual C# - OOP

Let your imaginations

Page 4: Unusual C# - OOP

I want you to know that we are learning :

Page 5: Unusual C# - OOP

Actually it’s

Usual C#

Page 6: Unusual C# - OOP

General Overview1. What is OOP ?2. What is class?3. Difference between class and object.4. The life cycle of an object:

A. Construction B. Destruction

5. The accessibility.6. Static Vs Instance.7. Reference type Vs. Value type.

8. OOP techniques.

Page 7: Unusual C# - OOP

What is OOP ?The difference between :

Object Oriented Programming andProcedure Oriented Programming.

Object Oriented Programming, why?

A real example : car manufacturing.

Page 8: Unusual C# - OOP

difference POP OOP

Importance given to the sequence of things to be done given to the data

larger programs divided into functions are divided into objects

functions share global data mostly the data is private

adding of data and function difficult easy

access modifier NO public, private and protected modifiers

Operator overload NO Yes

Page 9: Unusual C# - OOP

What is OOP ?The difference between :

Object Oriented Programming andProcedure Oriented Programming.

Object Oriented Programming, why?

A real example : car manufacturing.

Page 10: Unusual C# - OOP

What is class?• Class is a great container .• Has some members like : (constructor, properties,

fields, Methods, Variables, statements, …).• It has some features which are given to its

instances.

• Class like : Department

Page 11: Unusual C# - OOP

Difference between class and object:

• What is an object ?object is a building block of an OOP application, this building

block encapsulates part of the application.

• Objects are created from types, these types of an object is known by classes.

• The object is an instance of a class.• We treat with classes through objects.• “every thing is object”

Page 12: Unusual C# - OOP

The life cycle of an object:

• The object has three cases:

1. Construction.1. Default constructor is often public.2. What if it become private?

2. Being in use.3. Destruction.

Page 13: Unusual C# - OOP

The accessibility• Determine which code can access these

members that is whether they are available to all code ( public ) or only to code within the class ( private ).

• The modifier ( protected ).• We can make fields privates and provide access

to them via public properties.(the encapsulation)

Page 14: Unusual C# - OOP

Static Vs Instance• Static members are shared between instances of

the class.

• When using static members you needn’t to instantiate an object.

• To use Instance members you must instantiate an object from the class.

Page 15: Unusual C# - OOP

Reference type Vs Value type

Page 16: Unusual C# - OOP

OOP techniques

• Encapsulation.• Abstract.• Interface.• Inheritance.• Polymorphism.

Page 17: Unusual C# - OOP

Encapsulation

• Making fields privates and provide access to them via public properties.

• Classes Idea is encapsulation.• Why encapsulation ?

Page 18: Unusual C# - OOP

Abstract• Abstract class is a class that may or may not contain abstract

methods.

• Abstract class can’t be instantiated.

• An abstract method is a method that is declared without an implementation.

• If a class includes abstract methods, the class itself must be declared abstract.

Page 19: Unusual C# - OOP

Interface• If an abstract class contains only abstract method

declarations, it should be declared as an interface instead.

• Interface can’t be instantiated.

• You can implement interface in an inherited class.

• Imagine the interface as a contract between interface creator and class consumers.

Page 20: Unusual C# - OOP

Inheritance• Child class inherited from (derived from) parent class (base

class).• In C#, you may derive only from a single base class directly.• You can override a member in child class that is virtual in the

parent class.• A class may be sealed.• C# provide a common base class for all objects called object.

Page 21: Unusual C# - OOP

Polymorphism

• It is very useful for performing tasks with a minimum of code on different objects from a single class.

• Overriding & Overloading.• Polymorphism means that :

you can use the same instruction with different return value into screen.

Page 22: Unusual C# - OOP

Practice

Page 23: Unusual C# - OOP

Any Questions ?

I have some questions !!

Page 24: Unusual C# - OOP

Can you allow class to be inherited, but prevent the

method from being over-ridden?

Yes, just leave the class public and make the method sealed.

Page 25: Unusual C# - OOP

Can you override private virtual methods?

No, you cannot access private methods in inherited classes.

Page 26: Unusual C# - OOP

Can you declare the override method static while the original

method is non-static?

No, you can't, the signature of the virtual method must remain the same, only the

keyword virtual is changed to keyword override

Page 27: Unusual C# - OOP

The last question..

Is it true or false , and why ?

False , Because its constructor is private

Page 28: Unusual C# - OOP

Contact me for any inquiryMedhatDawoud[at]Gmail.com ..E-mail me..twitter.com/Med7atDawoud ..follow me..

Med7at.wordpress.com ..Current Blog..

www.MedhatDawoud.com

..Coming soon..

Page 29: Unusual C# - OOP

Thanks for listening