Object Oriented Design Principles - SOLID

download Object Oriented Design Principles - SOLID

If you can't read please download the document

Transcript of Object Oriented Design Principles - SOLID

Object Oriented DesignPrinciples with silly names but help you code more betterer.

SOLID

FREDDY NOSTRILS

Illegal Muppets

1. Single Responsibility Principle

Classes should only have one reason for change

Border Patrol

patrol_border

accept_illegal_shipments_of_muppets

DAMN POSTAL STRIKE!

Border guards can't patrol whilst waiting for packages

2. Open/Closed Principle

Classes Should be Open for Extension but Closed for Modification

Border Guard

accept_tequila_bribe

Border Guard

accept_bribe(bribe)

Look for the Abstractions!

Liskov Substitution Principle

Subtype should be completely substitutable for the Supertype

Border Guard

drink(Fluid)

!=

Although Freddy Will be Happy the Guards' Boss won't be!

Interface Segregation Principle

Clients should not be forced to depend on methods they do not use.

Freddy

Shipment

Airhole

Illegal Muppets

circulate_air(airholes_count)

ship

IllegalShipment

Dependency Inversion Principle

High Level Business Logic shouldn't depend on lower level details.

-find muppets-pack muppets-bribe border patrol-phone pedro to come and pick up muppets.-celebrate

Freddy's Business Logic:

What's the problem here?