Object Oriented Programing
[OOP]
Revision
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
Binding
Reference From Parent => Object From Child
● Static binding works during compile time
● Compiler Will Bind Function Call Based On Reference Type Not Object Type
● Dynamic binding works during run time
● CLR Will Bind Function Call Based On Object Type Not Reference Type
Session 04
Session
Content
1. Interface
2. Deep Copy And Shallow Copy
3. Built In Interface [ICloneable]
4. Built In Interface [IComparable]
5. Built In Interface [IComparer]
Interface
Interf
ace
C# Keywords Indicate The Accessibility Scope
What You Can Write Inside The Interface
1. Signature for Property
2. Signature for Method
3. Default Implemented Method
C# Keywords Indicate The Accessibility Scope
● Default Access Modifier Inside Interface => Public
● Default Access Modifier of Interface => Internal
● Private Access Modifier is not allowed inside interface
● You Can not Create an object from interface but you can
create a reference from interface
● Interface is a Code Contract Between 2 Developers
● Interface Can Be Implemented Through Class Or Struct
Interf
ace
C# Keywords Indicate The Accessibility Scope
Interf
ace
Shallow Copy and Deep
Copy
[Array Of Value Type]
Shallow Copy :
Stack Heap
int[] Arr01 = { 1, 2, 3 };
int[] Arr02 = new int[3];
Arr01
2 3
0 0 0
Arr02
Arr02 = Arr01;
Arr01[0] = 10;
1
10
Console.WriteLine($"Arr01[0] = {Arr01[0]}");
Console.WriteLine($"Arr02[0] = {Arr01[0]}");
// 10
//10
Object
Identity Object State
[Address] [ 1, 2,3]
Deep Copy :
Stack Heap
int[] Arr01 = { 1, 2, 3 };
int[] Arr02 = new int[3];
Arr01
2 3
0 0 0
Arr02
Arr02 = (int[])Arr01.Clone();
Arr01[0] = 10;
1
10
Console.WriteLine($"Arr01[0] = {Arr01[0]}");
Console.WriteLine($"Arr02[0] = {Arr01[0]}");
// 10
// 1
1 2 3
Object
Identity Object State
[Address] [ 1, 2,3]
Shallow Copy and Deep
Copy
[Array of Reference
Type]
Array Of String
[Immutable]
Shallow Copy :
Stack Heap
String[] Names01 = new String[1]
Names01[0] = “Omar”;
Names01
SRef01
SRef02
Names02
string[] Names02 = new string[1];
Names02 = Names01;
Names02[0] = “Aya”;
Omar
Aya
CWL($"Name01[0].Name = {Names01[0]}");
CWL($"Name02[0].Name = {Names02[0]}");
Deep Copy :
Stack Heap
String[] Names01 = new String[1]
Names01[0] = “Omar”;
Names01
SRef01
SRef02
Names02
string[] Names02 = new string[1];
Names02 = (string[])Names01.Clone();
Names01[0] = “Aya”;
Omar
Aya
CWL($"Name01[0].Name = {Names01[0]}");
CWL($"Name02[0].Name = {Names02[0]}");
SRef01
Array Of
StringBuilder[Mutable]
Shallow Copy :
Stack Heap
StringBuilder[] Names01 = new StringBuilder[1]
Names01[0] = new StringBuilder("Omar");
Names01
SBRef01
SBRef02
Names02
StringBuilder[] Names02 = new StringBuilder[1];
Names02 = Names01;
Names02[0].Append("Ahmed");
Omar
OmarAhmed
CWL($"Name01[0].Name = {Names01[0]}");
CWL($"Name02[0].Name = {Names02[0]}");
Deep Copy :
Stack Heap
StringBuilder[] Names01 = new StringBuilder[1]
Names01[0] = new StringBuilder("Omar");
Names01
SBRef01
SBRef02
Names02
StringBuilder[] Names02 = new StringBuilder[1];
Names02 = (StringBuilder[])Names01.Clone();
Names02[0].Append("Ahmed");
Omar
OmarAhmed
CWL($"Name01[0].Name = {Names01[0]}");
CWL($"Name02[0].Name = {Names02[0]}");
SBRef01
Sort :

Object-oriented programming using C# programming language 04

  • 1.
  • 2.
  • 3.
    Relationships Between Classes 1. Inheritance2. Association FulltimeEmployee : Employee Fulltime Employee is A Employee
  • 4.
    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
  • 7.
    Binding Reference From Parent=> Object From Child
  • 8.
    ● Static bindingworks during compile time ● Compiler Will Bind Function Call Based On Reference Type Not Object Type ● Dynamic binding works during run time ● CLR Will Bind Function Call Based On Object Type Not Reference Type
  • 9.
  • 10.
    Session Content 1. Interface 2. DeepCopy And Shallow Copy 3. Built In Interface [ICloneable] 4. Built In Interface [IComparable] 5. Built In Interface [IComparer]
  • 11.
  • 12.
    Interf ace C# Keywords IndicateThe Accessibility Scope What You Can Write Inside The Interface 1. Signature for Property 2. Signature for Method 3. Default Implemented Method
  • 13.
    C# Keywords IndicateThe Accessibility Scope ● Default Access Modifier Inside Interface => Public ● Default Access Modifier of Interface => Internal ● Private Access Modifier is not allowed inside interface ● You Can not Create an object from interface but you can create a reference from interface ● Interface is a Code Contract Between 2 Developers ● Interface Can Be Implemented Through Class Or Struct Interf ace
  • 14.
    C# Keywords IndicateThe Accessibility Scope Interf ace
  • 15.
    Shallow Copy andDeep Copy [Array Of Value Type]
  • 16.
    Shallow Copy : StackHeap int[] Arr01 = { 1, 2, 3 }; int[] Arr02 = new int[3]; Arr01 2 3 0 0 0 Arr02 Arr02 = Arr01; Arr01[0] = 10; 1 10 Console.WriteLine($"Arr01[0] = {Arr01[0]}"); Console.WriteLine($"Arr02[0] = {Arr01[0]}"); // 10 //10 Object Identity Object State [Address] [ 1, 2,3]
  • 17.
    Deep Copy : StackHeap int[] Arr01 = { 1, 2, 3 }; int[] Arr02 = new int[3]; Arr01 2 3 0 0 0 Arr02 Arr02 = (int[])Arr01.Clone(); Arr01[0] = 10; 1 10 Console.WriteLine($"Arr01[0] = {Arr01[0]}"); Console.WriteLine($"Arr02[0] = {Arr01[0]}"); // 10 // 1 1 2 3 Object Identity Object State [Address] [ 1, 2,3]
  • 18.
    Shallow Copy andDeep Copy [Array of Reference Type]
  • 19.
  • 20.
    Shallow Copy : StackHeap String[] Names01 = new String[1] Names01[0] = “Omar”; Names01 SRef01 SRef02 Names02 string[] Names02 = new string[1]; Names02 = Names01; Names02[0] = “Aya”; Omar Aya CWL($"Name01[0].Name = {Names01[0]}"); CWL($"Name02[0].Name = {Names02[0]}");
  • 21.
    Deep Copy : StackHeap String[] Names01 = new String[1] Names01[0] = “Omar”; Names01 SRef01 SRef02 Names02 string[] Names02 = new string[1]; Names02 = (string[])Names01.Clone(); Names01[0] = “Aya”; Omar Aya CWL($"Name01[0].Name = {Names01[0]}"); CWL($"Name02[0].Name = {Names02[0]}"); SRef01
  • 22.
  • 23.
    Shallow Copy : StackHeap StringBuilder[] Names01 = new StringBuilder[1] Names01[0] = new StringBuilder("Omar"); Names01 SBRef01 SBRef02 Names02 StringBuilder[] Names02 = new StringBuilder[1]; Names02 = Names01; Names02[0].Append("Ahmed"); Omar OmarAhmed CWL($"Name01[0].Name = {Names01[0]}"); CWL($"Name02[0].Name = {Names02[0]}");
  • 24.
    Deep Copy : StackHeap StringBuilder[] Names01 = new StringBuilder[1] Names01[0] = new StringBuilder("Omar"); Names01 SBRef01 SBRef02 Names02 StringBuilder[] Names02 = new StringBuilder[1]; Names02 = (StringBuilder[])Names01.Clone(); Names02[0].Append("Ahmed"); Omar OmarAhmed CWL($"Name01[0].Name = {Names01[0]}"); CWL($"Name02[0].Name = {Names02[0]}"); SBRef01
  • 25.