Understanding Software Layering and Object Composition

partitioning and layering fundamentals n.w
1 / 23
Embed
Share

Learn the fundamentals of software layering, object composition, and reducing dependencies to adapt to change in software development. Explore the concepts of types, objects, behavior, and interfaces to write efficient applications.

  • Software Development
  • Layering
  • Object Composition
  • Fundamentals
  • Interfaces

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

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 Complex Type class Employee { string name; void Pay() . } 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 Engine { string manufacturer; int horsepower; class Wheel { string manufacturer; float tirePressure; } void Start(){ }; void Stop(){ }; void Turn(){ }; }

  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 Interfaces describe behavior, not implementation interface IEngine { void Start(); void Stop(); } interface IWheel { void Turn(); }

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

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

  15. Interfaces Hide Implementation class Diesel: IEngine { string manufacturer; int horsepower; class WankelEngine : IEngine { string manufacturer; int rotationSpeed; } } void Start () { } void Stop() { } 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 Content