shooting at a moving target

15
SHOOTING AT A MOVING TARGET Software development is … İrem Küçükali

Upload: irem-kuecuekali

Post on 11-Feb-2017

89 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Shooting at a Moving Target

SHOOTING AT A MOVING TARGET

Software development is …

İrem Küçükali

Page 2: Shooting at a Moving Target

• Requirements change.• Software should be designed iteratively. Each iteration aims to

improve the design for it to be as good as it can be for the current situation of the system.• Being agile leads keeping design flexible and easy to change.• Never let the rot begin.

Page 3: Shooting at a Moving Target

Clues of Rotting Software• Rigidity: Don’t write everyting in one place & use abstractions

• Fragility: Ex. callback hells

• Immobility: Don’t write intricate code

• Viscosity: Preserving the design is hard.

• Needless Complexity: Weight of unused design.

• Needless Repetition: Don’t copy-paste the same code over and over.

• Opacity: Difficult to understand

Page 4: Shooting at a Moving Target

And How To Avoid Them• Rigidity• Fragility• Immobility• Viscosity• Needless Complexity• Needless Repetition• Opacity

• S ingle Responsibility• O pen Closed• L iskov Substitution• I nterface Segregation• D ependency Inversion

PRINCIPLES

Page 5: Shooting at a Moving Target

Single Responsibility Principle• A class should have only one reason to change.• Having multiple responsibility on a class may cause rebuild, retest and

redeploy all dependent applications just because one of them needed to change.

Page 6: Shooting at a Moving Target

Open Closed Principle• Extendible without modifying• Uses abstract classes and derivatives to extend• Avoids recompilation• Avoids Fragility by saving us from countless if/else statements• Avoids Rigidity since there would be no need for changes in existing

modules.• Avoids Immobility by creating seperable modules not affected by

changes in each other• Abstractions can save us from changes (only) that we anticipated.

Page 7: Shooting at a Moving Target

Open Closed Principle• Not complete, but strategic closure.• Strategic: experiences, educated guesses• Applying OCP, only for likely changes.• Wait until need abstraction.• Flexible, reusable, maintainable.

Page 8: Shooting at a Moving Target

To See Earlier The Changes That Are Likely• Write tests first.• Release early and often.

Page 9: Shooting at a Moving Target

Liskov Substitution Principle• Subtypes must be substitutiable for their base types.• Violated by fragile functions with respect to classes with IS-A hierarchy• IS-A relationship concerns behaviour• Validity can only be expressed in terms of clients.• Design by Contract:

• Base class > Derived class• Unit tests indicate contracts

• To avoid LSP violation, superclasses representing the classes with IS-A relationship may be used• Set of classes sharing same responsibility should inherit it from a superclass

• In that way, it would be easier to add a new subclass sharing same responsibility.

Page 10: Shooting at a Moving Target

Liskov Substitution Principle• LSP makes OCP possible.• IS-A does not mean subtype.

Page 11: Shooting at a Moving Target

Clues about LSP Violations• Derivative doing less than its base class is usually violates LSP.• Derivative throwing an exception whose base don’t throw them is

another form of violation.

Page 12: Shooting at a Moving Target

Dependency Inversion Principle• To be mobile/reusable and flexible, high-level modules should depend on

abstraction(interfaces) instead of low-level modules.• Changes to lower-level modules cannot affect and change high-level

modules• Services through a well-designed and controlled interface• Lower layers depend on abstract service interfaces declared in upper layers• Depending on abstractions

• No reference to concrete classes• No derivative of concrete classes• No overriding implemented methods of base classes

Page 13: Shooting at a Moving Target

Dependency Inversion Principle• Seperating policy from implementation• Nobody owns the interface

Page 14: Shooting at a Moving Target

Interface Segregation Principle• Interface pollution: When derivatives needs a new method, that

method will be added to the base class• Multiple inheritance can be used to conform ISP• Using same object through seperate inte

Page 15: Shooting at a Moving Target

References Next…