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

Anton Shemerey: Refactoring and SOLID principles in Ruby.

Jul 13, 2015

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Anton Shemerey: Refactoring and SOLID principles in Ruby.

ruby solid principles

&& refactoring

Al2O3

Anton Shemerey

@shemerey

Page 2: Anton Shemerey: Refactoring and SOLID principles in Ruby.
Page 3: Anton Shemerey: Refactoring and SOLID principles in Ruby.

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

Page 4: Anton Shemerey: Refactoring and SOLID principles in Ruby.

Al2O3

Page 5: Anton Shemerey: Refactoring and SOLID principles in Ruby.

S the most important one-

Page 6: Anton Shemerey: Refactoring and SOLID principles in Ruby.

each object should have

only a single responsibility

Page 7: Anton Shemerey: Refactoring and SOLID principles in Ruby.
Page 8: Anton Shemerey: Refactoring and SOLID principles in Ruby.

First step is extraction

Page 9: Anton Shemerey: Refactoring and SOLID principles in Ruby.

open/closed principle

problem

Page 10: Anton Shemerey: Refactoring and SOLID principles in Ruby.

object should be open for extension, but closed for modification

Page 11: Anton Shemerey: Refactoring and SOLID principles in Ruby.

Liskov substitution principle

Page 12: Anton Shemerey: Refactoring and SOLID principles in Ruby.

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.

Page 13: Anton Shemerey: Refactoring and SOLID principles in Ruby.

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.

Page 14: Anton Shemerey: Refactoring and SOLID principles in Ruby.
Page 15: Anton Shemerey: Refactoring and SOLID principles in Ruby.

Interface segregation

Page 16: Anton Shemerey: Refactoring and SOLID principles in Ruby.

Clients should not be

forced to depend on

methods that they do

not use.

Page 17: Anton Shemerey: Refactoring and SOLID principles in Ruby.
Page 18: Anton Shemerey: Refactoring and SOLID principles in Ruby.

arguments black whole

Page 19: Anton Shemerey: Refactoring and SOLID principles in Ruby.
Page 20: Anton Shemerey: Refactoring and SOLID principles in Ruby.
Page 21: Anton Shemerey: Refactoring and SOLID principles in Ruby.

Dependency inversion principle

• depend upon abstractions, do not depend upon concretions

Page 22: Anton Shemerey: Refactoring and SOLID principles in Ruby.
Page 23: Anton Shemerey: Refactoring and SOLID principles in Ruby.

• Constants

• Instance variables

• Public methods

Data Encapsulation

Page 24: Anton Shemerey: Refactoring and SOLID principles in Ruby.