This document introduces object-oriented programming concepts including classes, inheritance, encapsulation, and polymorphism. It discusses how OOP allows for more organized and flexible code through the use of classes, objects, and methods. Key aspects of classes like constructors, destructors, and access modifiers are explained. Other concepts covered include static vs non-static classes, method overloading, enumerations, structures, abstract classes, interfaces, and abstract methods. The document aims to provide an overview of fundamental OOP principles.
Why OOP ? •More Organized Code . • Debug Fast . • Fast to Find Errors . • More Flexible To use .
7.
Classes : - •It’s A container to A Collection of Methods . • It’s Reference Type . • Constructors “is a Method With The Same Name Of The Class” . • Destructors “is a Method With The Same Name Of The Class With ~ Before the Name”. Ex : Class Persone { Public Persone() { //Code } ~ Persone() { //Code } }
8.
Static And NonStatic Class • Non Static Class To Us It Must Make Instance . Ex : Person p = new Person(); p.Speak(); • Static Class You Can Us It Direct . Ex : Console.WriteLine(“Hello MVA”); • How To Make A static Class . Ex : Static Class Person { Private Void Speak() { } }
9.
OverLoading : - •Over Loading Is A Group Of Methods Have The Same Name ! Ex : Public Void Speak (int Num); Public Void Speak (int Num ,String Txt); Ex : MessageBox.Show(String Text); MessageBox.Show(String Text,String Caption); MessageBox.Show(String Text , String Caption , Message BoxButtons Button);
10.
Access Modifier :- • Public : “ Calling From Any Place “ . • Private : “ Only Calling From The Same Class “ . • Protected : “ Only Calling From The Inherit Class “ . • Internal : “ Only Calling From The Current Assembly File Only “ . • Protected Intenal : “ Can Calling From The Inherit Class And From The Current Assembly File “ .
11.
Enumeration : - •It’s a Group Of Element’s To Represent Cases and Different Values Inside The Program . EX : enum Human { Male=0; Female=1; } • Using Name Of enum Only But Real Value stored as a byte So We Can Use It at (Windows API) .
12.
Structures : - •Is a special Types To Upload any Properties and Behaviors as variables Or Methods . Stuct Human { Public String JobTitle; Public int Age; Public int Year; }; Human Mahmoud =new Human(); Mahmoud.JobTitle=“Developer”; Mahmoud.Age=22; Mahmoud.Year=2015; • Struct Can Have an Item Is Another Struct . • Struct Is a Value Type .
13.
Encapsulation : - •Is Hide Our Code And Use It As a Black Box From The Final Method . • using Access Modifier . EX : Human Ahmed =new Ahmed(); Ahmed.Age=6723896349; • We Can Use Get(Accessor) And Set (Mutator). EX : Person { Private int Age; Public Get Age (int age) { If(age <=100 $$ age>=1) { Age=age; } else{console.WriteLine(“We Can’t store This Age”);} } }
14.
Encapsulation (Type Property): - Class Person { Public int Age { get{return Age ; } set{if (Age<=100 $$ Age>1) Age=Value;} } }
15.
Inheritance : - •What Is Inheritance Mean ?! . • Is-a Relation . • Has-a Relation . • When I can Use Inheritance ?! . • Multi Inheritance ! . EX : Class Developer : Human { // Implementation }
16.
Inheritance (Saled“Not Inheritable”): - Saled Class Human { } This Way Is Wrong ! Class Teacher : Human × {} • You Can Only Use From Object’s . • Human Teacher =new Human();
17.
Abstract Classes (MustInherit):- • Is A class Must Inherit To Use his attributes From The Inherited Class . EX : abstract class Human { Public int Age; } EX : class Doctor :Hman { }
18.
Interface : - •Is abstract Class With Out Any Implementation . Interface Human { int Age ; String JobTitle; int Year; } • More Than Once Inherit .
19.
Polymorphism : - •You Can Create Class With Out Any Implementation . • You Can Change Methods Implementation by Overriding between two Different Classes. Public Virtual void Speak() { Console,Beep(); } Public Override void Speak() { Console.WriteLine(“Speak”); }
20.
Abstract Methods :- • Is a Kind Of Polymorphism but abstract Key Word Forcing The Developer To Make Override . Public abstract void Speak() { Console,Beep(); } Public Override void Speak() { Console.WriteLine(“Speak”); }