SlideShare a Scribd company logo
1 of 72
Object-Oriented Programming Fundamental Concepts ,[object Object],[object Object],[object Object]
Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Fundamental Principles of OOP
Fundamental Principles of OOP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance
Classes and Interfaces ,[object Object],[object Object],[object Object],[object Object],[object Object],public class Labyrinth { … } public interface IFigure { … }
Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],derived class base class / parent class inherits derived interface base interface implements class interface implements
Inheritance – Benefits ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance – Example Person +Name: String +Address: String Employee +Company: String +Salary: double Student +School: String Base class Derived class Derived class
Class Hierarchies ,[object Object],… Game MultiplePlayersGame BoardGame Chess Backgammon SinglePlayerGame Minesweeper Solitaire …
Inheritance in .NET ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How to Define  Inheritance ? ,[object Object],[object Object],public class Shape {...} public class Circle : Shape {...} public Circle (int x, int y) : base(x) {...}
Simple Inheritance Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simple Inheritance Example  (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
S imple  Inheritance  ,[object Object]
Accessibility Levels ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance and Accessibility ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance and Accessibility (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance and Accessibility ,[object Object]
Inheritance: I mportant  A spect s ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance: Important Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstraction
Abstraction ,[object Object],[object Object],[object Object],"Relevant" to what?
Abstraction (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],Abstraction in .NET +Color : long ButtonBase +click() Control Button RadioButton CheckBox
Abstraction in .NET – Example System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ButtonBase System.Windows.Forms.Button
Interfaces in C# ,[object Object],[object Object],[object Object],[object Object],[object Object]
Abstract Classes in C# ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstract Data Types ,[object Object],[object Object],LinkedList<T> +Add(item : Object) +Remove(item : Object) +Clear() … «interface» IList<T> List<T>
Inheritance Hierarchies ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
UML Class Diagram – Example Shape #Position:Point struct Point +X:int +Y:int +Point interface ISurfaceCalculatable +CalculateSurface:float Rectangle -Width:float -Height:float +Rectangle +CalculateSurface:float Square -Size:float +Square +CalculateSurface:float FilledSquare -Color:Color +FilledSquare struct Color +RedValue:byte +GreenValue:byte +BlueValue:byte +Color FilledRectangle -Color:Color +FilledRectangle
Class Diagrams in Visual Studio ,[object Object]
Encapsulation
Encapsulation ,[object Object],[object Object],[object Object],[object Object],[object Object]
Encapsulation – Example ,[object Object],[object Object],Person -name : string -age : TimeSpan +Person(string name, int age) +Name : string { get; set; } +Age : TimeSpan { get; set; }
Encapsulation in .NET ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Encapsulation – Benefits ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Polymorphism
Polymorphism ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Polymorphism (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Virtual M ethod s   ,[object Object],[object Object],[object Object],public virtual void CalculateSurface()
The  override  Modifier ,[object Object],[object Object],[object Object],[object Object]
Polymorphism – How it Works? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Polymorphism – Example override CalcSurface()  { return size * size; } override CalcSurface()  { return PI * radius * raduis; } Abstract class Abstract action Concrete class Overriden action Overriden action Figure +CalcSurface() : double Square -x : int -y : int -size : int Circle -x : int -y : int -radius: int
Polymorphism – Example (2) abstract class Figure  {  public  abstract  double CalcSurface();  } abstract class Square  {  public  override  double CalcSurface() { return … } } Figure f1 = new Square(...); Figure f2 = new Circle(...); // This will call Square.CalcSurface() int surface = f1.CalcSurface(); // This will call Square.CalcSurface() int surface = f2.CalcSurface();
Polymorphism Live Demo
Class Hierarchies: Real World Example
Real World Example: Calculator ,[object Object],[object Object]
Real World Example: Calculator (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Real World Example: Calculator (3) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Real World Example: Calculator (4) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Calculator Classes  TextBox Paint() «interface» IPaintable -location -size -text -bgColor -faceColor -font Control Container Form Calculator AbstractButton Button CheckBox RadioButton MainMenu MenuItem Panel
Cohesion and Coupling
Cohesion ,[object Object],[object Object],[object Object],[object Object],[object Object]
Good and Bad Cohesion ,[object Object],[object Object]
Strong Cohesion ,[object Object],[object Object],[object Object],[object Object],[object Object],double sideA = 40, sideB = 69; double angleAB = Math.PI / 3; double sideC =  Math.Pow(sideA, 2) + Math.Pow(sideB, 2)  - 2 * sideA * sideB * Math.Cos(angleAB); double sidesSqrtSum = Math.Sqrt(sideA) +  Math.Sqrt(sideB) + Math.Sqrt(sideC);
Bad Cohesion ,[object Object],[object Object],[object Object],public void PrintDocument(Document d); public void SendEmail( string recipient, string subject, string text); public void CalculateDistanceBetweenPoints( int x1, int y1, int x2, int y2) MagicClass.MakePizza(&quot;Fat Pepperoni&quot;); MagicClass.WithdrawMoney(&quot;999e6&quot;); MagicClass.OpenDBConnection();
Coupling ,[object Object],[object Object],[object Object],[object Object],[object Object]
Loose and Tight Coupling ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Loose Coupling – Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Tight Coupling – Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Spaghetti Code ,[object Object],class Report { public void Print() {…} public void InitPrinter() {…} public void LoadPrinterDriver(string fileName) {…} public bool SaveReport(string fileName) {…} public void SetPrinter(string printer) {…} } class Printer { public void SetFileName() {…} public static bool LoadReport() {…} public static bool CheckReport() {…} }
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],Object-Oriented Programming Fundamental Concepts http://academy.telerik.com
Exercises ,[object Object],[object Object]
Exercises (2) ,[object Object]
Exercises (3) ,[object Object]
Exercises (4) ,[object Object]
Exercises (5) ,[object Object],[object Object]
Exercises (6) ,[object Object],[object Object],[object Object],[object Object]
Exercises (7) ,[object Object]

More Related Content

What's hot

Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
Inheritance
InheritanceInheritance
Inheritance
Tech_MX
 

What's hot (20)

07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
interface in c#
interface in c#interface in c#
interface in c#
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
inheritance
inheritanceinheritance
inheritance
 
Object oriented programming With C#
Object oriented programming With C#Object oriented programming With C#
Object oriented programming With C#
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Constructors in C++
Constructors in C++Constructors in C++
Constructors in C++
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Inheritance
InheritanceInheritance
Inheritance
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 

Viewers also liked

Oop’nin temel ilkeleri
Oop’nin temel ilkeleriOop’nin temel ilkeleri
Oop’nin temel ilkeleri
metehanates
 

Viewers also liked (11)

08. Numeral Systems
08. Numeral Systems08. Numeral Systems
08. Numeral Systems
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course Introduction
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
Technical Testing Introduction
Technical Testing IntroductionTechnical Testing Introduction
Technical Testing Introduction
 
Oop’nin temel ilkeleri
Oop’nin temel ilkeleriOop’nin temel ilkeleri
Oop’nin temel ilkeleri
 
Запознаване с Visual Basic. Основни форми и контроли
Запознаване с Visual Basic. Основни форми и контролиЗапознаване с Visual Basic. Основни форми и контроли
Запознаване с Visual Basic. Основни форми и контроли
 
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
 
Компютърна система
Компютърна системаКомпютърна система
Компютърна система
 
Whatsapp's Architecture
Whatsapp's ArchitectureWhatsapp's Architecture
Whatsapp's Architecture
 
WhatsApp architecture
WhatsApp architectureWhatsApp architecture
WhatsApp architecture
 

Similar to 20. Object-Oriented Programming Fundamental Principles

Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
Maryo Manjaruni
 
Object-Oriented Programming with C#
Object-Oriented Programming with C#Object-Oriented Programming with C#
Object-Oriented Programming with C#
Svetlin Nakov
 

Similar to 20. Object-Oriented Programming Fundamental Principles (20)

Object oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsObject oriented programming Fundamental Concepts
Object oriented programming Fundamental Concepts
 
20 Object-oriented programming principles
20 Object-oriented programming principles20 Object-oriented programming principles
20 Object-oriented programming principles
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Oops
OopsOops
Oops
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
C# program structure
C# program structureC# program structure
C# program structure
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
LectureNotes-02-DSA
LectureNotes-02-DSALectureNotes-02-DSA
LectureNotes-02-DSA
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
 
C# - Igor Ralić
C# - Igor RalićC# - Igor Ralić
C# - Igor Ralić
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Object-Oriented Programming with C#
Object-Oriented Programming with C#Object-Oriented Programming with C#
Object-Oriented Programming with C#
 
C# interview
C# interviewC# interview
C# interview
 
.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading
 

More from Intro C# Book

More from Intro C# Book (20)

17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
 
Java Problem solving
Java Problem solving Java Problem solving
Java Problem solving
 
21. Java High Quality Programming Code
21. Java High Quality Programming Code21. Java High Quality Programming Code
21. Java High Quality Programming Code
 
20.5 Java polymorphism
20.5 Java polymorphism 20.5 Java polymorphism
20.5 Java polymorphism
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
20.2 Java inheritance
20.2 Java inheritance20.2 Java inheritance
20.2 Java inheritance
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arrays
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
 
01. Introduction to programming with java
01. Introduction to programming with java01. Introduction to programming with java
01. Introduction to programming with java
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

20. Object-Oriented Programming Fundamental Principles

  • 1.
  • 2.
  • 4.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Inheritance – Example Person +Name: String +Address: String Employee +Company: String +Salary: double Student +School: String Base class Derived class Derived class
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 24.
  • 25.
  • 26.
  • 27. Abstraction in .NET – Example System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ButtonBase System.Windows.Forms.Button
  • 28.
  • 29.
  • 30.
  • 31.
  • 32. UML Class Diagram – Example Shape #Position:Point struct Point +X:int +Y:int +Point interface ISurfaceCalculatable +CalculateSurface:float Rectangle -Width:float -Height:float +Rectangle +CalculateSurface:float Square -Size:float +Square +CalculateSurface:float FilledSquare -Color:Color +FilledSquare struct Color +RedValue:byte +GreenValue:byte +BlueValue:byte +Color FilledRectangle -Color:Color +FilledRectangle
  • 33.
  • 35.
  • 36.
  • 37.
  • 38.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45. Polymorphism – Example override CalcSurface() { return size * size; } override CalcSurface() { return PI * radius * raduis; } Abstract class Abstract action Concrete class Overriden action Overriden action Figure +CalcSurface() : double Square -x : int -y : int -size : int Circle -x : int -y : int -radius: int
  • 46. Polymorphism – Example (2) abstract class Figure { public abstract double CalcSurface(); } abstract class Square { public override double CalcSurface() { return … } } Figure f1 = new Square(...); Figure f2 = new Circle(...); // This will call Square.CalcSurface() int surface = f1.CalcSurface(); // This will call Square.CalcSurface() int surface = f2.CalcSurface();
  • 48. Class Hierarchies: Real World Example
  • 49.
  • 50.
  • 51.
  • 52.
  • 53. Calculator Classes TextBox Paint() «interface» IPaintable -location -size -text -bgColor -faceColor -font Control Container Form Calculator AbstractButton Button CheckBox RadioButton MainMenu MenuItem Panel
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.

Editor's Notes

  1. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  2. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  3. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  4. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## Extensibility / Polymorphism: New functionality may be easily plugged in without changing existing classes as long the new plug-in classes extend given base classes. Reusability: For a set of similar applications a framework can be defined using a core set of classes that are to be extended by classes that fill in the application-dependent part. Information Hiding: If a more general class using a simpler contract is sufficient, details from extending classes may be hidden to some of the client classes. This allows them to be more independent from possible changes and diminishes the load of contracts that must be understood by a reader of these client classes. * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  5. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  6. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  7. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  8. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##
  9. (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.(c) 2006 National Academy for Software Development - http://academy.devbg.org* ## * 07/16/96 (c) 2006 National Academy for Software Development - http://academy.devbg.org* ##