Presentation is loading. Please wait.

Presentation is loading. Please wait.

Partitioning and Layering Fundamentals. The Basic Problem Change is a fact of life RequirementsTechnologies Bug Fixes Software Must Adapt.

Similar presentations


Presentation on theme: "Partitioning and Layering Fundamentals. The Basic Problem Change is a fact of life RequirementsTechnologies Bug Fixes Software Must Adapt."— Presentation transcript:

1 Partitioning and Layering Fundamentals

2 The Basic Problem Change is a fact of life RequirementsTechnologies Bug Fixes Software Must Adapt

3 Solution: Software Layers Reduce software coupling Minimize the consequences of change Focused Unit Tests to verify change Example of Code Refactoring

4 Fundamental Concepts Difference between a type and an object Complex type CompositionInterface

5 Type class Employee { string name; … void Pay() ….} Data Behavior Simple Type Complex Type

6 Object Employee emp = new Employee();

7 Object Composition class Auto { Engine engine; Wheel[4] wheels; void Drive() {…}; }

8 class Engine { string manufacturer; int horsepower; void Start(){…}; void Stop(){…}; } class Wheel { string manufacturer; float tirePressure; void Turn(){…}; } Object composition introduces dependencies

9 Write your so that the dependencies of one type on another are eliminated or minimized. Write your applications so that the dependencies of one type on another are eliminated or minimized.

10 Make types dependent on type's behavior, not its implementation.

11 Unit tests verify that a type's behavior is correct.

12 Interfaces interface IEngine { void Start(); void Stop(); } interface IWheel { void Turn(); } Interfaces describe behavior, not implementation

13 Rewritten Engine, Wheel Classes class Engine : IEngine { string manufacturer; int horsepower; void Start () {…} void Stop() {…} } class Wheel : IWheel { string manufacturer float tirePressure; void Turn(); }

14 Interface Composition class Auto { IEngine engine; IWheel[4] wheels; void Drive() {…} }

15 Interfaces Hide Implementation class Diesel: IEngine { string manufacturer; int horsepower; void Start () {…} void Stop() {…} } class WankelEngine : IEngine { string manufacturer; int rotationSpeed; void Start () {…} void Stop() {…} }

16 Coupling Preserve Essential Coupling Essential Semantics Remove Inessential Coupling Programming Artifacts

17 Electrical Analogy Wall socket interface removes the inessential coupling due to the physical shape of plugs and appliances An interface cannot remove the essential behavioral coupling of voltage and amperage of standard current

18 Complexity vs. Flexibility Interfaces add a level of indirection Put interfaces along application fault lines Hard to refactor out of a bad design

19 Interfaces vs. Inheritance Favor interface over object composition Interface Composition vs. Inheritance? class RacingCar : HighPerformanceCar : Auto class RacingCar : HighPerformanceCar : Auto Static Definition Need to Understand Base Class Behavior

20 "Inheritance Breaks Encapsulation" class HighPerformanceCar { virtual void Start() {TurnIgnition(); Press GasPedal(); }…} class RacingCar : HighPerformanceCar {…}

21 Interfaces Avoid Inheriting Implementation Restrict Inessential Coupling Make Interfaces Easy to Modify

22 Design Patterns Minimize Dependencies in Implementation Use Design Patterns Electrical Analogy Design to work with 110 or 220 volts? Use Transformer Pattern Flexibility even with Essential Coupling

23 Summary Reduce coupling and dependencies of complex types Use Interface Based Design Use Composition rather than Implementation Inheritance Write unit tests to validate behavior


Download ppt "Partitioning and Layering Fundamentals. The Basic Problem Change is a fact of life RequirementsTechnologies Bug Fixes Software Must Adapt."

Similar presentations


Ads by Google