1 / 23

Partitioning and Layering Fundamentals

Partitioning and Layering Fundamentals. The Basic Problem. Change is a fact of life Requirements Technologies Bug Fixes Software Must Adapt. Solution: Software Layers. Reduce software coupling Minimize the consequences of change Focused Unit Tests to verify change

briar
Download Presentation

Partitioning and Layering Fundamentals

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Partitioning and Layering Fundamentals

  2. The Basic Problem Change is a fact of life Requirements Technologies 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 Composition Interface

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

  6. Object Employee emp = new Employee();

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

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

  9. 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 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

More Related