Unusual C# - OOP
-
Upload
medhat-dawoud -
Category
Technology
-
view
1.256 -
download
1
description
Transcript of Unusual C# - OOP
![Page 1: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/1.jpg)
Unusual C#OOP Gate
Prepared & Presented by:Eng. : Medhat Dawoud
![Page 2: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/2.jpg)
Relax your self
![Page 3: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/3.jpg)
Let your imaginations
![Page 4: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/4.jpg)
I want you to know that we are learning :
![Page 5: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/5.jpg)
Actually it’s
Usual C#
![Page 6: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/6.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/7.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/8.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/9.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/10.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/11.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/12.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/13.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/14.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/15.jpg)
Reference type Vs Value type
![Page 16: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/16.jpg)
OOP techniques
• Encapsulation.• Abstract.• Interface.• Inheritance.• Polymorphism.
![Page 17: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/17.jpg)
Encapsulation
• Making fields privates and provide access to them via public properties.
• Classes Idea is encapsulation.• Why encapsulation ?
![Page 18: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/18.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/19.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/20.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/21.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/22.jpg)
Practice
![Page 23: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/23.jpg)
Any Questions ?
I have some questions !!
![Page 24: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/24.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/25.jpg)
Can you override private virtual methods?
No, you cannot access private methods in inherited classes.
![Page 26: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/26.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/27.jpg)
The last question..
Is it true or false , and why ?
False , Because its constructor is private
![Page 28: Unusual C# - OOP](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/28.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022061613/555a6681d8b42ae7218b4b18/html5/thumbnails/29.jpg)
Thanks for listening