OOP (Object Oriented Programming )
Disadvantage of traditional programming ?
1- Difficult maintenance 2- slow development 3- difficult to read and update
Advantage of OOP ?
1- Easy maintenance 2- fast development 3- easy to read , organized code ,
modularity
OOP : collection of objects
Object : is instance of class and saved in memory
Class : is blueprint template describe the details of object
OOP Concepts ?
1- Encapsulation 2- inheritance 3- polymorphism 4- abstraction
Encapsulation ?
First face : group of elements have the same state (variables) and behavior package(methods) in
model (class)
Second face : data hidden
Name space : is a container to classes and allow to organize code in the shape of development
Nested name space : is container for name spaces and classes
Inheritance : ability to create new classes from existing class
Inheritance gool : reusing of code
Is a relationship : used to describe relationship between subclass and super class in inheritance case
Has a relationship : used to describe relationship between class and other class where first class
taken object from the last class
Sealed modifier : make this class can’t any class inherit from it
Diamond problem : 1-Class can inherit from only one class
2-Class can’t inherit from many classes
Access modifiers : key word added to declaration of class or class member (methods) to allow
restrict their accessibility
Types of access modifiers :
Public – private – protected – internal – protected internal
1- Public : access is not restricted
any method in class can saw any class even if in the same assembly file or other
assembly file
2- Private : 1-access is limited to containing type
2-Class or method can saw from only class it self or its method
When any class inherit from it , class can’t see private methods
3- Protected : 1-access is limited to containing class or types derived from containing class
2-Is similar to private except protected method showed to class inherit from it
even if in the same assembly file or other assembly file
4- Internal : access is limited to current assembly package
it shown to any class in the same assembly file even if in other name space
5- Protected internal : 1-access is limited to current assembly or types derived from containing
class
2- Is a union between internal modifier and protected modifier
3-Any class can inherit from it even if in the same assembly file or in other
assembly file and show methods in class
Constructor : used to initialize the data members during the object initialization
Constructor Guides :
1- Constructor is special method of class used to create valid instance of class
2- Constructor doesn’t have return type not even void
3- Constructor take the shape of method and don’t have return type or keyword
4- Class can have any number of constructor (overloading )
5- Constructor name should be the same as class name
6- Constructor have access modifiers
7- To exit from constructor use return statement
Types of Constructor ?
1- User-defined Constructor 2- default constructor
User-defined Constructor : Passing value during create class inherit from class
Default constructor : initialize data members with default value corresponding to data member
types
This keyword :1- used to differentiate class member and local member
2- Refer to current object of current class
Static member : functions don’t have this pointer
Static used for 1- variables 2- methods 3- constructor 4- class
Static class : 1- all methods in class must be static
2-Single copy to be shared all instance of class
3-Shared variables or shared methods when give value to method in class then all objects
inherit the same value
static constructor :
1- class have only one static constructor
2- static constructor has to be parameter less
3- static constructor can’t have any access modifier
4- it used to initialize static data members of class
5- for any number of object creation static constructor get executed only one
6- static constructor get executed when class get need for very first timeline application
7- static constructor can’t be invoked by programmer explicitly
polymorphism : 1- it mean many shapes
2-is ability to have many different forms to on shape
Polymorphism appear with : overloading 2- over riding 3- inheritance
Overloading : ability to define several methods all with the same name but in different signature
Different signature mean : changing of access modifiers or data type or number of variables
Over riding : class have the same name as method in base class to improve performance or add new
functionality
Over riding purpose :
Add new functionality or enhance method performance
Cancel the old implementation of method and write new
Keywords used for over ridded method ?
1- virtual 2- over ride 3- new 4- abstract
1- virtual : key word used to modify method declaration and allow it to be over ridden in derived
class
2- over ride : 1-modifier is required to extend or modify the abstract or virtual implementation of
inherited method
2-used to override on existing method in sub class
3- new : 1-when used as modifier new keyword hide member inherited from base class
2-hiding inherited methods mean that derived versions of the member replace the base
class