SlideShare uma empresa Scribd logo
1 de 15
Reservations Gateway Inc.Reservations Gateway Inc.
YOUR LINK to e-TRAVEL SOLUTIONSYOUR LINK to e-TRAVEL SOLUTIONS
December 2013
- OO Design Principles -- OO Design Principles -
Creating ROBUST ApplicationsCreating ROBUST Applications
““Any intelligent fool can make things bigger and more complex...Any intelligent fool can make things bigger and more complex...
It takes a touch of genius - and a lot of courage to move in theIt takes a touch of genius - and a lot of courage to move in the
opposite directionopposite direction””
- Albert Einstein- Albert Einstein
Indika Maligaspe
Intro...Intro...
December 2013
Indika Maligaspe

K. Indika Maligaspe

Developer, Designer, Architect , Trainer

Tech Geek specialized in JAVA and .Net

Over 13 years if experience in IT / Web Technologies

Lover of almost all sports...

http://www.linkedin.com/profile/view?id=201732082&trk=nav_responsive_tab_profile
December 2013

Design SmellsDesign Smells

Being SOLIDBeing SOLID

SRP – ?SRP – ?

OCP – ?OCP – ?

LSP – ?LSP – ?

ISP – ?ISP – ?

DIP – ?DIP – ?

QAQA
What we will coverWhat we will cover
Indika Maligaspe
December 2013

Rigidity – Difficult to ChangeRigidity – Difficult to Change

Fragility – Can easily break (Xmas Tree)Fragility – Can easily break (Xmas Tree)

Immobility – Hard to Re-UseImmobility – Hard to Re-Use

Viscosity – Need of Hacks vs MethodsViscosity – Need of Hacks vs Methods
Design SmellsDesign Smells
Indika Maligaspe
December 2013

Rigidity – Difficult to ChangeRigidity – Difficult to Change

Fragility – Can easily break (Xmas Tree)Fragility – Can easily break (Xmas Tree)

Immobility – Hard to Re-UseImmobility – Hard to Re-Use

Viscosity – Need of Hacks vs MethodsViscosity – Need of Hacks vs Methods
Design SmellsDesign Smells
Indika Maligaspe
December 2013

Five Design Principles to overcome Design SmellsFive Design Principles to overcome Design Smells

Not easy to implement yet neededNot easy to implement yet needed

Not a Rule, but a Guide LineNot a Rule, but a Guide Line

Can be implemented anytime, but earlier is BESTCan be implemented anytime, but earlier is BEST

Every Software Engineer should know ofEvery Software Engineer should know of
What is SOLIDWhat is SOLID
Indika Maligaspe
December 2013
SRP - SingleSRP - Single
Responsibility PrincipleResponsibility Principle
Indika Maligaspe
An Object should have one and ONLY one reason to changeAn Object should have one and ONLY one reason to change
public class ErrorLogManager{
public void logToFile(){
// Open File
// Check file size and if over limit create a new one
// write to File
// Close File
}
public void logToDatabase{
// Open Connection
// write to Db
// Close Connection
}
}
December 2013
A module should be Open for extensionA module should be Open for extension
and Close for Modificationand Close for Modification
Indika Maligaspe
OCP – Open/Close PrincipleOCP – Open/Close Principle
public class ErrorLogger{
public void log(ILogSource source){
//Logging Code
}
}
public interface ILogSource{
logError(Exception err);
}
public class FileLogSourcer implements ILogSource{
public void logError(){
// Open File
// Check file size and if over limit create a new one
// write to File
// Close File
}
}
public class DatabaseLogSourcer implements ILogSource{
public void logError(){
// Open Connection
// write to Db
// Close Connection
}
}
December 2013
Methods that use references to the base classes must beMethods that use references to the base classes must be
able to use the objects of the derived classes without knowing it.able to use the objects of the derived classes without knowing it.
LSP - Liskov Substitution PrincipleLSP - Liskov Substitution Principle
Indika Maligaspe
Children should not break Parent ClassesChildren should not break Parent Classes
class Bird {
public void fly(){}
public void eat(){}
}
class Parrot extends Bird {}
class Ostrich extends Bird{
fly(){
throw new UnsupportedOperationException();
}
}
public BirdTest{
public static void main(String[] args){
List<Bird> birdList = new ArrayList<Bird>();
birdList.add(new Parrot());
birdList.add(new Ostrich());
letsFly (birdList );
}
static void letsFly ( List<Bird> birdList ){
for ( Bird b : birdList ) {
b.fly();
}
}
}
December 2013
LSP - Liskov Substitution PrincipleLSP - Liskov Substitution Principle
contd.....contd.....
Indika Maligaspe
class Bird{
public void eat(){}
}
class FlyingBirds extends Bird{
public void fly(){}
}
class NonFlyingBirds extends Bird{
public void walk(){}
}
class Ostrich extends NonFlyingBirds{
walk(){
}
}
How to identify LSP Violation?How to identify LSP Violation?
Derived class may require less functionalities than the Base class, so some methods would be redundant.
We might be using IS-A to check for Super-Sub relationships, but LSP doesn’t use only IS-A,
but it also requires that the Sub types must be substitutable for the Super class. And one cannot decide the
substitutability of sub class in isolation. One has to consider how the clients of the class hierarchy are going to use it.
December 2013
ISP – Interface Segregation PrincipleISP – Interface Segregation Principle
Indika Maligaspe
Make fine grained interfaces that are client specificMake fine grained interfaces that are client specific
public interface IAnimal {
void fly();
void run();
void bark();
}
public class Bird implements IAnimal {
public void bark() { /* do nothing */ }
public void run() {
// bird running code
}
public void fly() {
// bird flying code
}
}
public class Cat implements IAnimal {
public void fly() { throw new Exception("Undefined cat property"); }
public void bark() { throw new Exception("Undefined cat property"); }
public void run() {
// cat running code
}
}
public class Dog implements IAnimal {
public void fly() { }
public void bark() {
// dog barking code
}
public void run() {
// dog running code
}
}
December 2013
ICP – Interface Segregation PrincipleICP – Interface Segregation Principle
contd....contd....
Indika Maligaspe
public interface IFlyable {
void fly();
}
public interface IRunnable {
void run();
}
public interface IBarkable {
void bark();
}
public class Bird implements IFlyable, IRunnable {
public void run() {
// running bird code
}
public void fly() {
// flying bird code
}
}
public class Cat implements IRunnable{
public void run() {
// running cat code
}
}
public class Dog implements IRunnable, IBarkable {
public void bark() {
// barking dog code
}
public void run() {
// running dog code
}
}
December 2013
DIP - Dependency Inversion PrincipleDIP - Dependency Inversion Principle
Indika Maligaspe
Depend on abstraction , not concretions.Depend on abstraction , not concretions.
““Abstraction” should not depend upon “Details”. DetailsAbstraction” should not depend upon “Details”. Details
should depend upon abstractionshould depend upon abstraction
class Worker {
public void work() {
// ....working
}
}
class Manager {
Worker worker;
public void setWorker(Worker w) {
worker = w;
}
public void manage() {
worker.work();
}
}
class ShiftWorker {
public void work() {
//.... working much more
}
}
We have to change the Manager class
Some of the current functionality from the manager class might be affected.
The unit testing should be redone.
December 2013
DIP - Dependency Inversion PrincipleDIP - Dependency Inversion Principle contd....contd....
Indika Maligaspe
interface IWorker {
public void work();
}
class Worker implements IWorker{
public void work() {
// ....working
}
}
class ShiftWorker implements IWorker{
public void work() {
//.... working much more
}
}
class Manager {
IWorker worker;
public void setWorker(IWorker w) {
worker = w;
}
public void manage() {
worker.work();
}
}
Manager class doesn't require changes when adding ShiftWorkers.
Minimized risk to affect old functionality present in Manager class since we don't change it.
No need to redo the unit testing for Manager class.
December 2013
Indika Maligaspe
Thank You
Reservations Gateway Inc.Reservations Gateway Inc.
YOUR LINK to e-TRAVEL SOLUTIONSYOUR LINK to e-TRAVEL SOLUTIONS
Reservations Gateway Inc.
Reservations Gateway Inc.
11654 Plaza America Drive , Unit 645
Reston, Virginia 20190-4700
USA
703 286 5331
703 433 0146
info@rezgateway.com
www.rezgateway.com
Tel :
Fax :
Email :
Web :

Mais conteúdo relacionado

Semelhante a Object Oriented Software Design Principles

The good, the bad and the SOLID
The good, the bad and the SOLIDThe good, the bad and the SOLID
The good, the bad and the SOLIDFrikkie van Biljon
 
RDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and BeyondRDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and BeyondFadi Maali
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)Mark Wilkinson
 
JavaScript Puzzlers!
JavaScript Puzzlers!JavaScript Puzzlers!
JavaScript Puzzlers!Charles Bihis
 
Spark forplainoldjavageeks svforum_20140724
Spark forplainoldjavageeks svforum_20140724Spark forplainoldjavageeks svforum_20140724
Spark forplainoldjavageeks svforum_20140724sdeeg
 
Open source report writing tools for IBM i Vienna 2012
Open source report writing tools for IBM i  Vienna 2012Open source report writing tools for IBM i  Vienna 2012
Open source report writing tools for IBM i Vienna 2012COMMON Europe
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Luciano Mammino
 
JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJosé Paumard
 
Don't Be STUPID, Grasp SOLID - DrupalCon Prague
Don't Be STUPID, Grasp SOLID - DrupalCon PragueDon't Be STUPID, Grasp SOLID - DrupalCon Prague
Don't Be STUPID, Grasp SOLID - DrupalCon PragueAnthony Ferrara
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)Jose Manuel Pereira Garcia
 
Apache Spark Introduction @ University College London
Apache Spark Introduction @ University College LondonApache Spark Introduction @ University College London
Apache Spark Introduction @ University College LondonVitthal Gogate
 
An Introduction to the SOLID Principles
An Introduction to the SOLID PrinciplesAn Introduction to the SOLID Principles
An Introduction to the SOLID PrinciplesAttila Bertók
 
Don't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionDon't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionAnthony Ferrara
 
Introduction to Apache Spark
Introduction to Apache Spark Introduction to Apache Spark
Introduction to Apache Spark Hubert Fan Chiang
 

Semelhante a Object Oriented Software Design Principles (20)

SOLID
SOLIDSOLID
SOLID
 
The good, the bad and the SOLID
The good, the bad and the SOLIDThe good, the bad and the SOLID
The good, the bad and the SOLID
 
RDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and BeyondRDF Analytics... SPARQL and Beyond
RDF Analytics... SPARQL and Beyond
 
Introduction to Domain-Driven Design
Introduction to Domain-Driven DesignIntroduction to Domain-Driven Design
Introduction to Domain-Driven Design
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
 
JavaScript Puzzlers!
JavaScript Puzzlers!JavaScript Puzzlers!
JavaScript Puzzlers!
 
Spark forplainoldjavageeks svforum_20140724
Spark forplainoldjavageeks svforum_20140724Spark forplainoldjavageeks svforum_20140724
Spark forplainoldjavageeks svforum_20140724
 
Open source report writing tools for IBM i Vienna 2012
Open source report writing tools for IBM i  Vienna 2012Open source report writing tools for IBM i  Vienna 2012
Open source report writing tools for IBM i Vienna 2012
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​
 
JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easy
 
Don't Be STUPID, Grasp SOLID - DrupalCon Prague
Don't Be STUPID, Grasp SOLID - DrupalCon PragueDon't Be STUPID, Grasp SOLID - DrupalCon Prague
Don't Be STUPID, Grasp SOLID - DrupalCon Prague
 
Sling Models Overview
Sling Models OverviewSling Models Overview
Sling Models Overview
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Apache Spark Introduction @ University College London
Apache Spark Introduction @ University College LondonApache Spark Introduction @ University College London
Apache Spark Introduction @ University College London
 
SOLID
SOLIDSOLID
SOLID
 
Sightly_techInsight
Sightly_techInsightSightly_techInsight
Sightly_techInsight
 
An Introduction to the SOLID Principles
An Introduction to the SOLID PrinciplesAn Introduction to the SOLID Principles
An Introduction to the SOLID Principles
 
Don't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionDon't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo Edition
 
Apache Pig
Apache PigApache Pig
Apache Pig
 
Introduction to Apache Spark
Introduction to Apache Spark Introduction to Apache Spark
Introduction to Apache Spark
 

Último

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Object Oriented Software Design Principles

  • 1. Reservations Gateway Inc.Reservations Gateway Inc. YOUR LINK to e-TRAVEL SOLUTIONSYOUR LINK to e-TRAVEL SOLUTIONS December 2013 - OO Design Principles -- OO Design Principles - Creating ROBUST ApplicationsCreating ROBUST Applications ““Any intelligent fool can make things bigger and more complex...Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in theIt takes a touch of genius - and a lot of courage to move in the opposite directionopposite direction”” - Albert Einstein- Albert Einstein Indika Maligaspe
  • 2. Intro...Intro... December 2013 Indika Maligaspe  K. Indika Maligaspe  Developer, Designer, Architect , Trainer  Tech Geek specialized in JAVA and .Net  Over 13 years if experience in IT / Web Technologies  Lover of almost all sports...  http://www.linkedin.com/profile/view?id=201732082&trk=nav_responsive_tab_profile
  • 3. December 2013  Design SmellsDesign Smells  Being SOLIDBeing SOLID  SRP – ?SRP – ?  OCP – ?OCP – ?  LSP – ?LSP – ?  ISP – ?ISP – ?  DIP – ?DIP – ?  QAQA What we will coverWhat we will cover Indika Maligaspe
  • 4. December 2013  Rigidity – Difficult to ChangeRigidity – Difficult to Change  Fragility – Can easily break (Xmas Tree)Fragility – Can easily break (Xmas Tree)  Immobility – Hard to Re-UseImmobility – Hard to Re-Use  Viscosity – Need of Hacks vs MethodsViscosity – Need of Hacks vs Methods Design SmellsDesign Smells Indika Maligaspe
  • 5. December 2013  Rigidity – Difficult to ChangeRigidity – Difficult to Change  Fragility – Can easily break (Xmas Tree)Fragility – Can easily break (Xmas Tree)  Immobility – Hard to Re-UseImmobility – Hard to Re-Use  Viscosity – Need of Hacks vs MethodsViscosity – Need of Hacks vs Methods Design SmellsDesign Smells Indika Maligaspe
  • 6. December 2013  Five Design Principles to overcome Design SmellsFive Design Principles to overcome Design Smells  Not easy to implement yet neededNot easy to implement yet needed  Not a Rule, but a Guide LineNot a Rule, but a Guide Line  Can be implemented anytime, but earlier is BESTCan be implemented anytime, but earlier is BEST  Every Software Engineer should know ofEvery Software Engineer should know of What is SOLIDWhat is SOLID Indika Maligaspe
  • 7. December 2013 SRP - SingleSRP - Single Responsibility PrincipleResponsibility Principle Indika Maligaspe An Object should have one and ONLY one reason to changeAn Object should have one and ONLY one reason to change public class ErrorLogManager{ public void logToFile(){ // Open File // Check file size and if over limit create a new one // write to File // Close File } public void logToDatabase{ // Open Connection // write to Db // Close Connection } }
  • 8. December 2013 A module should be Open for extensionA module should be Open for extension and Close for Modificationand Close for Modification Indika Maligaspe OCP – Open/Close PrincipleOCP – Open/Close Principle public class ErrorLogger{ public void log(ILogSource source){ //Logging Code } } public interface ILogSource{ logError(Exception err); } public class FileLogSourcer implements ILogSource{ public void logError(){ // Open File // Check file size and if over limit create a new one // write to File // Close File } } public class DatabaseLogSourcer implements ILogSource{ public void logError(){ // Open Connection // write to Db // Close Connection } }
  • 9. December 2013 Methods that use references to the base classes must beMethods that use references to the base classes must be able to use the objects of the derived classes without knowing it.able to use the objects of the derived classes without knowing it. LSP - Liskov Substitution PrincipleLSP - Liskov Substitution Principle Indika Maligaspe Children should not break Parent ClassesChildren should not break Parent Classes class Bird { public void fly(){} public void eat(){} } class Parrot extends Bird {} class Ostrich extends Bird{ fly(){ throw new UnsupportedOperationException(); } } public BirdTest{ public static void main(String[] args){ List<Bird> birdList = new ArrayList<Bird>(); birdList.add(new Parrot()); birdList.add(new Ostrich()); letsFly (birdList ); } static void letsFly ( List<Bird> birdList ){ for ( Bird b : birdList ) { b.fly(); } } }
  • 10. December 2013 LSP - Liskov Substitution PrincipleLSP - Liskov Substitution Principle contd.....contd..... Indika Maligaspe class Bird{ public void eat(){} } class FlyingBirds extends Bird{ public void fly(){} } class NonFlyingBirds extends Bird{ public void walk(){} } class Ostrich extends NonFlyingBirds{ walk(){ } } How to identify LSP Violation?How to identify LSP Violation? Derived class may require less functionalities than the Base class, so some methods would be redundant. We might be using IS-A to check for Super-Sub relationships, but LSP doesn’t use only IS-A, but it also requires that the Sub types must be substitutable for the Super class. And one cannot decide the substitutability of sub class in isolation. One has to consider how the clients of the class hierarchy are going to use it.
  • 11. December 2013 ISP – Interface Segregation PrincipleISP – Interface Segregation Principle Indika Maligaspe Make fine grained interfaces that are client specificMake fine grained interfaces that are client specific public interface IAnimal { void fly(); void run(); void bark(); } public class Bird implements IAnimal { public void bark() { /* do nothing */ } public void run() { // bird running code } public void fly() { // bird flying code } } public class Cat implements IAnimal { public void fly() { throw new Exception("Undefined cat property"); } public void bark() { throw new Exception("Undefined cat property"); } public void run() { // cat running code } } public class Dog implements IAnimal { public void fly() { } public void bark() { // dog barking code } public void run() { // dog running code } }
  • 12. December 2013 ICP – Interface Segregation PrincipleICP – Interface Segregation Principle contd....contd.... Indika Maligaspe public interface IFlyable { void fly(); } public interface IRunnable { void run(); } public interface IBarkable { void bark(); } public class Bird implements IFlyable, IRunnable { public void run() { // running bird code } public void fly() { // flying bird code } } public class Cat implements IRunnable{ public void run() { // running cat code } } public class Dog implements IRunnable, IBarkable { public void bark() { // barking dog code } public void run() { // running dog code } }
  • 13. December 2013 DIP - Dependency Inversion PrincipleDIP - Dependency Inversion Principle Indika Maligaspe Depend on abstraction , not concretions.Depend on abstraction , not concretions. ““Abstraction” should not depend upon “Details”. DetailsAbstraction” should not depend upon “Details”. Details should depend upon abstractionshould depend upon abstraction class Worker { public void work() { // ....working } } class Manager { Worker worker; public void setWorker(Worker w) { worker = w; } public void manage() { worker.work(); } } class ShiftWorker { public void work() { //.... working much more } } We have to change the Manager class Some of the current functionality from the manager class might be affected. The unit testing should be redone.
  • 14. December 2013 DIP - Dependency Inversion PrincipleDIP - Dependency Inversion Principle contd....contd.... Indika Maligaspe interface IWorker { public void work(); } class Worker implements IWorker{ public void work() { // ....working } } class ShiftWorker implements IWorker{ public void work() { //.... working much more } } class Manager { IWorker worker; public void setWorker(IWorker w) { worker = w; } public void manage() { worker.work(); } } Manager class doesn't require changes when adding ShiftWorkers. Minimized risk to affect old functionality present in Manager class since we don't change it. No need to redo the unit testing for Manager class.
  • 15. December 2013 Indika Maligaspe Thank You Reservations Gateway Inc.Reservations Gateway Inc. YOUR LINK to e-TRAVEL SOLUTIONSYOUR LINK to e-TRAVEL SOLUTIONS Reservations Gateway Inc. Reservations Gateway Inc. 11654 Plaza America Drive , Unit 645 Reston, Virginia 20190-4700 USA 703 286 5331 703 433 0146 info@rezgateway.com www.rezgateway.com Tel : Fax : Email : Web :