Object Oriented Programing
[OOP]
Revision
Access Modifiers
C# Keywords Indicate The Accessibility Scope
Access Modifiers
C# Keywords Indicate The Accessibility Scope
1. Private
2. Private Protected
3. Protected
4. Internal
5. Protected Internal
6. Public
From
Less
Accessible
To
Wider
Namesp
ace
C# Keywords Indicate The Accessibility Scope
What You Can Write Inside
Namespace ?
1. Class
2. Struct
3. Interface
4. Enum
Access Modifier Allowed Inside
Namespace ?
1. Internal [Default]
2. Public
Class Or
Struct
C# Keywords Indicate The Accessibility Scope
What You Can Write Inside The Struct Or Class
1. Attributes [Fields] => Member Variable
2. Functions [Constructor , Getter Setter , Method]
3. Properties [Full Property , Automatic Property , Indexer]
4. Events
Class Or
Struct
C# Keywords Indicate The Accessibility Scope
Access Modifier Allowed
Inside Struct?
1. Private [Default]
2. Internal
3. Public
Access Modifier Allowed
Inside Class?
1. Private [Default]
2. Private Protected
3. Protected
4. Internal
5. Protected Internal
6. Public
Interfa
ce
C# Keywords Indicate The Accessibility Scope
What You Can Write Inside The Interface ?
1. Signature For Property => C# 7.0
2. Signature For Method => C# 7.0
3. Default Implemented Method => C# 8.0 Feature .Net Core 3.1 [2019]
Enum
An enum type is a special data type that enables for a variable to be a set
of predefined constants
Delete
Write
Read
Execute
Bool [] Permissions = new bool[4];
Write Read Execute Delete
T F T F
1 bool : 1 byte
Bool[4] : 4 byte
1 byte : 8 bits
0 1
Write Read Execute Delete
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
128 64 32 16 8 4 2 1
Delete => 1
Execute => 2
Read => 4
Write => 8
Delete
Write
Read
Execute
Write Read Execute Delete
1 0 0 0
0 1 1 1
1 1 1 1
0 1 0 1
128 64 32 16 8 4 2 1
Delete => 1
Execute => 2
Read => 4
Write => 8
Decimal
8
7
15
5
Delete => 1
Execute => 2
Read => 4
Write => 8
1 => Delete
2 => Execute
3 => Delete , Execute
4 => Read
5 => Delete , Read
6 => Execute , Read
8 => Write
7 => Delete , Execute , Read
9 => Delete , Write
10 => Execute ,Write
11 => Delete , Execute , Write
12 => Read , Write
13 => Delete , Read , Write
14 => Execute , Read , Write
15 => Delete , Execute , Read , Write
Bitwise Operators :
& => And
| => OR
^ => XOR
// If You Want To Add Permission [Read] => Do [XOR] Operation
employee.Permissions = employee.Permissions ^ Permission.Read;
3 ^ 4
0 0 1 1
^
0 1 0 0
0 1 1 1 => 7
employee.Permissions = (Permission)3 ; // Delete , Execute
Console.WriteLine(employee.Permissions); // Delete , Execute , Read
// If You Want To Remove | Deny Permission [Read] => Do [XOR] Operation
employee.Permissions = employee.Permissions ^ Permission.Read;
7 ^ 4
0 1 1 1
^
0 1 0 0
0 0 1 1 => 3
employee.Permissions & Permission.Delete
3 & 1
0 0 1 1
&
0 0 0 1
0 0 0 1 => 1
// If You Want To Check Whether a Specific Permission is Existed or Not => DO [AND] Operation
Console.WriteLine(employee.Permissions); // Delete , Execute
(employee.Permissions & Permission.Delete) == permission.Delete // True
Bitwise Operators :
& => And
| => OR
^ => XOR
employee.Permissions = employee.Permissions | Permission.Delete
3 | 1
0 0 1 1
|
0 0 0 1
0 0 1 1 => 3
// If You Want To Add Permission => DO [OR] Operation
// OR => If Permission Existed -> Do Nothing
=> If Permission is not Existed -> Will Be Added
Console.WriteLine(employee.Permissions); // Delete , Execute
Bitwise Operators :
& => And
| => OR
^ => XOR
employee.Permissions = employee.Permissions | Permission.Read
3 | 4
0 0 1 1
|
0 1 0 0
0 1 1 1 => 7
Struct
Stru
ct
Stack
Point P1 ;
Y
X
8 Bytes
P1 = new Point(1,2);
2
1
Struct
● Value Type
● Support Encapsulation and
Overloading in Polymorphism
● Doesn’t Support Inheritance
● 3 Access Modifier Allowed
Inside It
● If You Defined a user defined
Constructor , Compiler Will
always Generate
Parameterless Constructor
Session 02
Session
Content
1. What Is OOP
2. Encapsulation
3. Property
4. Indexer
5. Class
6. Inheritance
7. Access Modifier
OOP Definition
OOP Consists Of 4 Pillars :
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
OOP Definition
OOP Consists Of 4 Pillars :
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
Encapsulation
Separate Data Definition [Attributes] From Its Use [Getter Setter , Property]
Encapsulatio
n
Stack
Employee Emp;
Salary
Name
Id
24 Bytes
Emp = new Employee (10 , “Aliaa” , 1000);
1000
10
StringRef
Heap
A M R
PhoneBook
Index
1
2
Indexer
Is a Special Property [Named With Keyword This and Can Take Parameters]
Class
Class
Clas
s
C# Keywords Indicate The Accessibility Scope
What You Can Write Inside The Class
1. Attributes [Fields] => Member Variable
2. Functions [Constructor , Getter Setter , Method]
3. Properties [Full Property , Automatic Property , Indexer]
4. Events
Cla
ss
C# Keywords Indicate The Accessibility Scope
Access Modifier Allowed Inside Class?
1. Private [Default]
2. Private Protected
3. Protected
4. Internal
5. Protected Internal
6. Public
Cla
ss
C# Keywords Indicate The Accessibility Scope
Constructor in Class :
● If There is no User defined Constructor , Compiler Will Always
Generate Empty Parameterless constructor => Will do Nothing .
● If You defined a User defined Constructor , Compiler Will No
Longer Generate Empty Parameterless constructor.
Cla
ss
Stack Heap
Car C1;
C1
C1 = new Car(10 , “BMW” , 290);
Speed
Model
Id
290
10
StringRef
B M W
16
Bytes
Class
VS
Struct
Stack VS Heap
Class VS
Struct
● Reference Type ● Value Type
● Support 4 Pillars Of OOP ● Support Encapsulation and
Overloading in Polymorphism
● More Flexible
● Doesn’t Support Inheritance
● 6 Access Modifier Allowed
Inside It
● Does Support Inheritance
● 3 Access Modifier Allowed
Inside It
● If You Defined a user defined
Constructor , Compiler Will no
longer Generate Empty
Parameterless Constructor
● If You Defined a user defined
Constructor , Compiler Will
always Generate
Parameterless Constructor
OOP Definition
OOP Consists Of 4 Pillars :
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
Parent
1. Int X
2. Int Y
3. Ctor (int X , int Y)
4. Method Product [X* Y]
Child
1. Int X
2. Int Y
3. Int Z
4. Ctor (int X , int Y ,int Z)
5. Method Product [X* Y*Z]
Access Modifiers
C# Keywords Indicate The Accessibility Scope
Access Modifiers
C# Keywords Indicate The Accessibility Scope
1. Private
2. Private Protected
3. Protected
4. Internal
5. Protected Internal
6. Public
From
Less
Accessible
To
Wider
Relationships Between
Classes
1. Inheritance 2. Association
FulltimeEmployee : Employee
Fulltime Employee is A Employee
Relationships Between
Classes
1. Inheritance 2. Association
Class Product { }
Class OrderItem
{ Product Product ; }
Association Composition
Class Chair{}
Class Room
{ chair[] Chairs; }
Orderitem Has a Product
Association Aggregation
Room Has Chairs

object oriented programming using C# programming langauge 02

  • 1.
  • 2.
  • 3.
    Access Modifiers C# KeywordsIndicate The Accessibility Scope
  • 4.
    Access Modifiers C# KeywordsIndicate The Accessibility Scope 1. Private 2. Private Protected 3. Protected 4. Internal 5. Protected Internal 6. Public From Less Accessible To Wider
  • 5.
    Namesp ace C# Keywords IndicateThe Accessibility Scope What You Can Write Inside Namespace ? 1. Class 2. Struct 3. Interface 4. Enum Access Modifier Allowed Inside Namespace ? 1. Internal [Default] 2. Public
  • 6.
    Class Or Struct C# KeywordsIndicate The Accessibility Scope What You Can Write Inside The Struct Or Class 1. Attributes [Fields] => Member Variable 2. Functions [Constructor , Getter Setter , Method] 3. Properties [Full Property , Automatic Property , Indexer] 4. Events
  • 7.
    Class Or Struct C# KeywordsIndicate The Accessibility Scope Access Modifier Allowed Inside Struct? 1. Private [Default] 2. Internal 3. Public Access Modifier Allowed Inside Class? 1. Private [Default] 2. Private Protected 3. Protected 4. Internal 5. Protected Internal 6. Public
  • 8.
    Interfa ce C# Keywords IndicateThe Accessibility Scope What You Can Write Inside The Interface ? 1. Signature For Property => C# 7.0 2. Signature For Method => C# 7.0 3. Default Implemented Method => C# 8.0 Feature .Net Core 3.1 [2019]
  • 9.
    Enum An enum typeis a special data type that enables for a variable to be a set of predefined constants
  • 10.
    Delete Write Read Execute Bool [] Permissions= new bool[4]; Write Read Execute Delete T F T F 1 bool : 1 byte Bool[4] : 4 byte 1 byte : 8 bits 0 1 Write Read Execute Delete 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 128 64 32 16 8 4 2 1 Delete => 1 Execute => 2 Read => 4 Write => 8
  • 11.
    Delete Write Read Execute Write Read ExecuteDelete 1 0 0 0 0 1 1 1 1 1 1 1 0 1 0 1 128 64 32 16 8 4 2 1 Delete => 1 Execute => 2 Read => 4 Write => 8 Decimal 8 7 15 5
  • 12.
    Delete => 1 Execute=> 2 Read => 4 Write => 8 1 => Delete 2 => Execute 3 => Delete , Execute 4 => Read 5 => Delete , Read 6 => Execute , Read 8 => Write 7 => Delete , Execute , Read 9 => Delete , Write 10 => Execute ,Write 11 => Delete , Execute , Write 12 => Read , Write 13 => Delete , Read , Write 14 => Execute , Read , Write 15 => Delete , Execute , Read , Write
  • 13.
    Bitwise Operators : &=> And | => OR ^ => XOR // If You Want To Add Permission [Read] => Do [XOR] Operation employee.Permissions = employee.Permissions ^ Permission.Read; 3 ^ 4 0 0 1 1 ^ 0 1 0 0 0 1 1 1 => 7 employee.Permissions = (Permission)3 ; // Delete , Execute Console.WriteLine(employee.Permissions); // Delete , Execute , Read // If You Want To Remove | Deny Permission [Read] => Do [XOR] Operation employee.Permissions = employee.Permissions ^ Permission.Read; 7 ^ 4 0 1 1 1 ^ 0 1 0 0 0 0 1 1 => 3
  • 14.
    employee.Permissions & Permission.Delete 3& 1 0 0 1 1 & 0 0 0 1 0 0 0 1 => 1 // If You Want To Check Whether a Specific Permission is Existed or Not => DO [AND] Operation Console.WriteLine(employee.Permissions); // Delete , Execute (employee.Permissions & Permission.Delete) == permission.Delete // True Bitwise Operators : & => And | => OR ^ => XOR
  • 15.
    employee.Permissions = employee.Permissions| Permission.Delete 3 | 1 0 0 1 1 | 0 0 0 1 0 0 1 1 => 3 // If You Want To Add Permission => DO [OR] Operation // OR => If Permission Existed -> Do Nothing => If Permission is not Existed -> Will Be Added Console.WriteLine(employee.Permissions); // Delete , Execute Bitwise Operators : & => And | => OR ^ => XOR employee.Permissions = employee.Permissions | Permission.Read 3 | 4 0 0 1 1 | 0 1 0 0 0 1 1 1 => 7
  • 16.
  • 17.
    Stru ct Stack Point P1 ; Y X 8Bytes P1 = new Point(1,2); 2 1
  • 18.
    Struct ● Value Type ●Support Encapsulation and Overloading in Polymorphism ● Doesn’t Support Inheritance ● 3 Access Modifier Allowed Inside It ● If You Defined a user defined Constructor , Compiler Will always Generate Parameterless Constructor
  • 19.
  • 20.
    Session Content 1. What IsOOP 2. Encapsulation 3. Property 4. Indexer 5. Class 6. Inheritance 7. Access Modifier
  • 21.
    OOP Definition OOP ConsistsOf 4 Pillars : 1. Encapsulation 2. Inheritance 3. Polymorphism 4. Abstraction
  • 22.
    OOP Definition OOP ConsistsOf 4 Pillars : 1. Encapsulation 2. Inheritance 3. Polymorphism 4. Abstraction
  • 23.
    Encapsulation Separate Data Definition[Attributes] From Its Use [Getter Setter , Property]
  • 25.
    Encapsulatio n Stack Employee Emp; Salary Name Id 24 Bytes Emp= new Employee (10 , “Aliaa” , 1000); 1000 10 StringRef Heap A M R
  • 26.
  • 27.
    Indexer Is a SpecialProperty [Named With Keyword This and Can Take Parameters]
  • 28.
  • 29.
  • 30.
    Clas s C# Keywords IndicateThe Accessibility Scope What You Can Write Inside The Class 1. Attributes [Fields] => Member Variable 2. Functions [Constructor , Getter Setter , Method] 3. Properties [Full Property , Automatic Property , Indexer] 4. Events
  • 31.
    Cla ss C# Keywords IndicateThe Accessibility Scope Access Modifier Allowed Inside Class? 1. Private [Default] 2. Private Protected 3. Protected 4. Internal 5. Protected Internal 6. Public
  • 32.
    Cla ss C# Keywords IndicateThe Accessibility Scope Constructor in Class : ● If There is no User defined Constructor , Compiler Will Always Generate Empty Parameterless constructor => Will do Nothing . ● If You defined a User defined Constructor , Compiler Will No Longer Generate Empty Parameterless constructor.
  • 33.
    Cla ss Stack Heap Car C1; C1 C1= new Car(10 , “BMW” , 290); Speed Model Id 290 10 StringRef B M W 16 Bytes
  • 34.
  • 35.
  • 36.
    Class VS Struct ● ReferenceType ● Value Type ● Support 4 Pillars Of OOP ● Support Encapsulation and Overloading in Polymorphism ● More Flexible ● Doesn’t Support Inheritance ● 6 Access Modifier Allowed Inside It ● Does Support Inheritance ● 3 Access Modifier Allowed Inside It ● If You Defined a user defined Constructor , Compiler Will no longer Generate Empty Parameterless Constructor ● If You Defined a user defined Constructor , Compiler Will always Generate Parameterless Constructor
  • 37.
    OOP Definition OOP ConsistsOf 4 Pillars : 1. Encapsulation 2. Inheritance 3. Polymorphism 4. Abstraction
  • 39.
    Parent 1. Int X 2.Int Y 3. Ctor (int X , int Y) 4. Method Product [X* Y] Child 1. Int X 2. Int Y 3. Int Z 4. Ctor (int X , int Y ,int Z) 5. Method Product [X* Y*Z]
  • 40.
    Access Modifiers C# KeywordsIndicate The Accessibility Scope
  • 41.
    Access Modifiers C# KeywordsIndicate The Accessibility Scope 1. Private 2. Private Protected 3. Protected 4. Internal 5. Protected Internal 6. Public From Less Accessible To Wider
  • 42.
    Relationships Between Classes 1. Inheritance2. Association FulltimeEmployee : Employee Fulltime Employee is A Employee
  • 43.
    Relationships Between Classes 1. Inheritance2. Association Class Product { } Class OrderItem { Product Product ; } Association Composition Class Chair{} Class Room { chair[] Chairs; } Orderitem Has a Product Association Aggregation Room Has Chairs