SlideShare a Scribd company logo
1 of 7
Download to read offline
OOP/UML Concepts
OOP
Inheritance
Inheritance occur when an object or a class is based on another object or a class. The idea is to reuse code
and therefore reducing maintenance time. Class based inheritance is used in languages like C++,Java and
C# while Object based inheritance (prototype) is used in languages such as JavaScript.
public class MyException : Exception
{
public MyException (string message, string extrainfo) : base(message)
{
//other stuff here
}
}
In this example MyException is a subclass of Exception. Above example also shows how to call the
base-class constructor in C#.
Encapsulation
Encapsulation is like hiding something inside a capsule and giving access to safe to use methods only.
Preventing unwanted access and avoiding risks. If Encapsulation is not used or not used properly it may
lead to spaghetti code. Encapsulation reduces the risks.
public class Employee {
private BigDecimal salary = new BigDecimal(50000.00);
public BigDecimal getSalary() {
return salary;
}
public static void main() {
Employee e = new Employee();
BigDecimal sal = e.getSalary();
}
}
class Program {
public class Account {
private decimal accountBalance = 500.00m;
public decimal CheckBalance() {
return accountBalance;
}
}
static void Main() {
Account myAccount = new Account();
decimal myBalance = myAccount.CheckBalance();
/* This Main method can check the balance via the public
* "CheckBalance" method provided by the "Account" class
* but it cannot manipulate the value of "accountBalance" */
}
}
Abstraction
Abstraction is used when you start your design process. You do not need to store all the details related to a
real world concept in an object. As an example when we are creating an employee management system and
we are using a class named Employee to identify an employee and there we do not need to store the length
of his/her fingers.
namespace EmployeeManagementSystem
{
public class Employee
{
private string address;
private string name;
private string telephone;
public string Address
{
get { return address; }
set { address = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Telephone
{
get { return telephone; }
set { telephone = value; }
}
public Employee(string name, string address, string telephone)
{
this.name = name;
this.address = address;
this.telephone = telephone;
}
}
}
Polymorphism
Overloading (Ad hoc polymorphism)
Overloaded methods are a part of polymorphism. It is the definition of multiple methods in same name but
accepts different set of parameters. In this example draw() is an overloaded method. Overloading means
that the same method name can be defined with more than one signature — the list of formal parameters
(and their types).
public class DataArtist {
...
public void draw(String s) {
...
}
public void draw(int i) {
...
}
public void draw(double f) {
...
}
public void draw(int i, double f) {
...
}
}
Subtyping
Subtyping allows you to use the concept of ‘code to an interface’ to generalize objects. AnnHalloway and
VictorBorga are musicians so they implement Musician interface. It is the ability to treat a class of
object as if it is the parent class (or interface).
public interface Musician {
public void play(Work work);
}
public interface Work {
public String getScript();
}
public class FugaAndToccata implements Work {
public String getScript() {
return Bach.getFugaAndToccataScript();
}
}
public class AnnHalloway implements Musician {
public void play(Work work) {
// plays in her own style, strict, disciplined
String script = work.getScript()
}
}
public class VictorBorga implements Musician {
public void play(Work work) {
// goofing while playing with superb style
String script = work.getScript()
}
}
public class Listener {
public void main(String[] args) {
Musician musician;
if (args!=null && args.length > 0 && args[0].equals("Anna")) {
musician = new AnnHalloway();
} else {
musician = new TerryGilliam();
}
musician.play(new FugaAndToccata());
}
Virtual Methods
Virtual method is a method that can be overridden by a subclass. In Java all methods are virtual by default
but in C# it has to be specified by the keyword virtual and overridden using override keyword.
//Java
public class A{
public int Test(){
return 0;
}
}
public class B extends A{
public int Test(){
return 1;
}
}
//usage
A a = new B();
int i = a.Test(); //1 is returned
//C#
public class A
{
public virtual int Test()
{
return 0;
}
}
public class B : A
{
public override int Test()
{
return 1;
}
}
//usage
A a = new B();
int I = a.Test(); //1 is returned
UML
Generalization
In the above example Cats and Dogs are subclasses of Mammals. They override walk() method. Mammals
is the super-class or the base-class of Cats and Dogs. Mammals is a generalized form of Cats and Dogs.
Cats and Dogs are specialized forms of Mamals.
The generalization relationship is also known as the inheritance or "is a" relationship.
Association
Person is a subscriber for Magazine. Person(s) subscribes Magazine(s). Magazine is a subscribed
magazine for Person. Association represents the static relationship shared among the objects of two classes.
Aggregation
A Professor has Students. This is the weak variant of “has a” relation. Aggregation can occur when a
class is a collection or container of other classes, but where the contained classes do not have a strong life
cycle dependency on the container—essentially, if the container is destroyed, its contents are not.
Composition
This is the strong variant of “has a” relation. Composition usually has a strong life cycle dependency
between instances of the container class and instances of the contained class(es): If the container is
destroyed, normally every instance that it contains is destroyed as well. (Note that, where allowed, a part
can be removed from a composite before the composite is deleted, and thus not be deleted as part of the
composite.)
References
 http://stackoverflow.com/questions/1031273/what-is-polymorphism
 http://stackoverflow.com/questions/56867/interface-vs-base-class
 http://en.wikipedia.org/wiki/Method_overriding
 http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29
 http://www.hiteshagrawal.com/uml/inheritance-in-uml
 http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29
 http://stackoverflow.com/questions/13123180/what-is-overloading-in-java
 http://lcp.org.uk/wp-content/uploads/2012/08/rewards.jpg
 http://en.wikipedia.org/wiki/Class_diagram
 http://stackoverflow.com/questions/12051/calling-base-constructor-in-c-sharp

More Related Content

What's hot

Object oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsObject oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsBharat Kalia
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental PrinciplesIntro C# Book
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++Swarup Kumar Boro
 
Class diagram- UML diagram
Class diagram- UML diagramClass diagram- UML diagram
Class diagram- UML diagramRamakant Soni
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in javaAtul Sehdev
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java yash jain
 
Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationshipsPooja mittal
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAhmed Nobi
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Java OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceJava OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceOUM SAOKOSAL
 

What's hot (20)

Object oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsObject oriented programming Fundamental Concepts
Object oriented programming Fundamental Concepts
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 
Class diagram
Class diagramClass diagram
Class diagram
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
Class diagram- UML diagram
Class diagram- UML diagramClass diagram- UML diagram
Class diagram- UML diagram
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Abstract method
Abstract methodAbstract method
Abstract method
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
 
Inheritance in java
Inheritance in java Inheritance in java
Inheritance in java
 
Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationships
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
2 class use case
2 class use case2 class use case
2 class use case
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
class diagram
class diagramclass diagram
class diagram
 
Java OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceJava OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & Interface
 
Uml class-diagram
Uml class-diagramUml class-diagram
Uml class-diagram
 
Class diagram
Class diagramClass diagram
Class diagram
 

Viewers also liked

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...Isuru Perera
 
OOP - Understanding association, aggregation, composition and dependency
OOP - Understanding association, aggregation, composition and dependencyOOP - Understanding association, aggregation, composition and dependency
OOP - Understanding association, aggregation, composition and dependencyMudasir Qazi
 
UML Class Diagram G-3-122139
UML Class Diagram G-3-122139UML Class Diagram G-3-122139
UML Class Diagram G-3-122139Hansi Thenuwara
 
Object diagram
Object diagramObject diagram
Object diagramRahul Pola
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingMoutaz Haddara
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagramsbarney92
 

Viewers also liked (7)

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...
 
OOP - Understanding association, aggregation, composition and dependency
OOP - Understanding association, aggregation, composition and dependencyOOP - Understanding association, aggregation, composition and dependency
OOP - Understanding association, aggregation, composition and dependency
 
UML Class Diagram G-3-122139
UML Class Diagram G-3-122139UML Class Diagram G-3-122139
UML Class Diagram G-3-122139
 
Object diagram
Object diagramObject diagram
Object diagram
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagrams
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 

Similar to OOP Concepets and UML Class Diagrams

Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritancemanish kumar
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.pptEmanAsem4
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 
Obect-Oriented Collaboration
Obect-Oriented CollaborationObect-Oriented Collaboration
Obect-Oriented CollaborationAlena Holligan
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesSunil Kumar Gunasekaran
 

Similar to OOP Concepets and UML Class Diagrams (20)

Chap11
Chap11Chap11
Chap11
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritance
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Design pattern
Design patternDesign pattern
Design pattern
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Java02
Java02Java02
Java02
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
Obect-Oriented Collaboration
Obect-Oriented CollaborationObect-Oriented Collaboration
Obect-Oriented Collaboration
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Core java oop
Core java oopCore java oop
Core java oop
 
Java 06
Java 06Java 06
Java 06
 

Recently uploaded

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 

Recently uploaded (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 

OOP Concepets and UML Class Diagrams

  • 1. OOP/UML Concepts OOP Inheritance Inheritance occur when an object or a class is based on another object or a class. The idea is to reuse code and therefore reducing maintenance time. Class based inheritance is used in languages like C++,Java and C# while Object based inheritance (prototype) is used in languages such as JavaScript. public class MyException : Exception { public MyException (string message, string extrainfo) : base(message) { //other stuff here } } In this example MyException is a subclass of Exception. Above example also shows how to call the base-class constructor in C#. Encapsulation Encapsulation is like hiding something inside a capsule and giving access to safe to use methods only. Preventing unwanted access and avoiding risks. If Encapsulation is not used or not used properly it may lead to spaghetti code. Encapsulation reduces the risks. public class Employee { private BigDecimal salary = new BigDecimal(50000.00); public BigDecimal getSalary() { return salary; } public static void main() { Employee e = new Employee(); BigDecimal sal = e.getSalary(); } } class Program { public class Account { private decimal accountBalance = 500.00m; public decimal CheckBalance() { return accountBalance; } }
  • 2. static void Main() { Account myAccount = new Account(); decimal myBalance = myAccount.CheckBalance(); /* This Main method can check the balance via the public * "CheckBalance" method provided by the "Account" class * but it cannot manipulate the value of "accountBalance" */ } } Abstraction Abstraction is used when you start your design process. You do not need to store all the details related to a real world concept in an object. As an example when we are creating an employee management system and we are using a class named Employee to identify an employee and there we do not need to store the length of his/her fingers. namespace EmployeeManagementSystem { public class Employee { private string address; private string name; private string telephone;
  • 3. public string Address { get { return address; } set { address = value; } } public string Name { get { return name; } set { name = value; } } public string Telephone { get { return telephone; } set { telephone = value; } } public Employee(string name, string address, string telephone) { this.name = name; this.address = address; this.telephone = telephone; } } } Polymorphism Overloading (Ad hoc polymorphism) Overloaded methods are a part of polymorphism. It is the definition of multiple methods in same name but accepts different set of parameters. In this example draw() is an overloaded method. Overloading means that the same method name can be defined with more than one signature — the list of formal parameters (and their types). public class DataArtist { ... public void draw(String s) { ... } public void draw(int i) { ... } public void draw(double f) { ... } public void draw(int i, double f) { ... } }
  • 4. Subtyping Subtyping allows you to use the concept of ‘code to an interface’ to generalize objects. AnnHalloway and VictorBorga are musicians so they implement Musician interface. It is the ability to treat a class of object as if it is the parent class (or interface). public interface Musician { public void play(Work work); } public interface Work { public String getScript(); } public class FugaAndToccata implements Work { public String getScript() { return Bach.getFugaAndToccataScript(); } } public class AnnHalloway implements Musician { public void play(Work work) { // plays in her own style, strict, disciplined String script = work.getScript() } } public class VictorBorga implements Musician { public void play(Work work) { // goofing while playing with superb style String script = work.getScript() } } public class Listener { public void main(String[] args) { Musician musician; if (args!=null && args.length > 0 && args[0].equals("Anna")) { musician = new AnnHalloway(); } else { musician = new TerryGilliam(); } musician.play(new FugaAndToccata()); } Virtual Methods Virtual method is a method that can be overridden by a subclass. In Java all methods are virtual by default but in C# it has to be specified by the keyword virtual and overridden using override keyword. //Java public class A{ public int Test(){ return 0;
  • 5. } } public class B extends A{ public int Test(){ return 1; } } //usage A a = new B(); int i = a.Test(); //1 is returned //C# public class A { public virtual int Test() { return 0; } } public class B : A { public override int Test() { return 1; } } //usage A a = new B(); int I = a.Test(); //1 is returned
  • 6. UML Generalization In the above example Cats and Dogs are subclasses of Mammals. They override walk() method. Mammals is the super-class or the base-class of Cats and Dogs. Mammals is a generalized form of Cats and Dogs. Cats and Dogs are specialized forms of Mamals. The generalization relationship is also known as the inheritance or "is a" relationship. Association Person is a subscriber for Magazine. Person(s) subscribes Magazine(s). Magazine is a subscribed magazine for Person. Association represents the static relationship shared among the objects of two classes. Aggregation A Professor has Students. This is the weak variant of “has a” relation. Aggregation can occur when a class is a collection or container of other classes, but where the contained classes do not have a strong life cycle dependency on the container—essentially, if the container is destroyed, its contents are not.
  • 7. Composition This is the strong variant of “has a” relation. Composition usually has a strong life cycle dependency between instances of the container class and instances of the contained class(es): If the container is destroyed, normally every instance that it contains is destroyed as well. (Note that, where allowed, a part can be removed from a composite before the composite is deleted, and thus not be deleted as part of the composite.) References  http://stackoverflow.com/questions/1031273/what-is-polymorphism  http://stackoverflow.com/questions/56867/interface-vs-base-class  http://en.wikipedia.org/wiki/Method_overriding  http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29  http://www.hiteshagrawal.com/uml/inheritance-in-uml  http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29  http://stackoverflow.com/questions/13123180/what-is-overloading-in-java  http://lcp.org.uk/wp-content/uploads/2012/08/rewards.jpg  http://en.wikipedia.org/wiki/Class_diagram  http://stackoverflow.com/questions/12051/calling-base-constructor-in-c-sharp