Unusual C# OOP Gate Prepared & Presented by: Eng. : Medhat Dawoud
May 19, 2015
Unusual C#OOP Gate
Prepared & Presented by:Eng. : Medhat Dawoud
Relax your self
Let your imaginations
I want you to know that we are learning :
Actually it’s
Usual C#
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.
What is OOP ?The difference between :
Object Oriented Programming andProcedure Oriented Programming.
Object Oriented Programming, why?
A real example : car manufacturing.
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
What is OOP ?The difference between :
Object Oriented Programming andProcedure Oriented Programming.
Object Oriented Programming, why?
A real example : car manufacturing.
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
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”
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.
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)
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.
Reference type Vs Value type
OOP techniques
• Encapsulation.• Abstract.• Interface.• Inheritance.• Polymorphism.
Encapsulation
• Making fields privates and provide access to them via public properties.
• Classes Idea is encapsulation.• Why encapsulation ?
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.
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.
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.
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.
Practice
Any Questions ?
I have some questions !!
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.
Can you override private virtual methods?
No, you cannot access private methods in inherited classes.
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
The last question..
Is it true or false , and why ?
False , Because its constructor is private
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..
Thanks for listening