24
ruby solid principles && refactoring Al2O3 Anton Shemerey @shemerey

Anton Shemerey: Refactoring and SOLID principles in Ruby

Embed Size (px)

Citation preview

ruby solid principles

&& refactoring

Al2O3

Anton Shemerey

@shemerey

Some History about SOLID

• Single responsibility principle: an object should have only a single

responsibility. 1979

• Open/closed principle: an object should be open for extension, but

closed for modification. 1988

• Liskov substitution principle: objects in a program should be

replaceable with instances of their subtypes without altering the

correctness of that program 1987

• Interface segregation principle: many client specific interfaces are

better than one general purpose interface. 1995

• Dependency inversion principle: depend upon abstractions, do not

depend upon concretions 1996

Al2O3

S the most important one-

each object should have

only a single responsibility

First step is extraction

open/closed principle

problem

object should be open for extension, but closed for modification

Liskov substitution principle

Let q(x) be a property provable

about objects x of type T. Then q(y)

should be provable for objects y of

type S, where S is a subtype of T.

Bla q(x) bl a blablabl blablabla bla

blablabla bla bla Bla. Bla q(y)

BlaBla bla blablabla bla blabla b

la bla S, where S is a blablabla T.

Interface segregation

Clients should not be

forced to depend on

methods that they do

not use.

arguments black whole

Dependency inversion principle

• depend upon abstractions, do not depend upon concretions

• Constants

• Instance variables

• Public methods

Data Encapsulation