Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution.

Similar presentations


Presentation on theme: "Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution."— Presentation transcript:

1 Introduction to SOLID Principles

2 Background

3 Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution Principle Interface Segregation Principle

4 S: Single Responsibility Principle (SRP) “Every class should have a single responsibility, and that responsibility should be entirely encapsulated by that class”

5

6 1.When we need to modify the way we save Customer data 2.When we want to revise the way we log our Exceptions The Customer class has 2 reasons to change:

7

8

9 Difficulty in naming classes can be a sign that you are trying to do too much, and that this class is taking on too much responsibility Do One Thing: methods that only do one thing are usually very short: 3-5 lines Multiple unit tests for the same method should be a warning sign that you are doing too much SRP - Tips

10 O: Open/Closed Principle (OCP) “Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”

11 O: Open/Closed Principle (OCP) Open for extension – you can extend an object’s behaviour Closed for modification – without the need to modify any existing code

12

13

14

15 L: Liskov Substitution Principle (LSP) “If S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of that program”

16

17

18

19

20

21 Favour Interfaces over inheritance (Google this…you’ll find loads!) Use inheritance sparingly. Keep inheritance hierarchies from getting to big – aim for no more than two or three deep. LSP - Tips

22 I: Interface Segregation Principle (ISP) “No client should be forced to depend on methods it does not use.”

23

24

25

26

27

28

29 D: Dependency Inversion Principle (DIP) “A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend on details. Details should depend on abstractions.”

30

31

32

33 Unity Castle Windsor IOC Containers

34

35 Questions

36 Follow Us Dave Cook http://tech.comparethemarket.com/author/cookie/ @dcook_net @thectmers


Download ppt "Introduction to SOLID Principles. Background Dependency Inversion Principle Single Responsibility Principle Open/Closed Principle Liskov Substitution."

Similar presentations


Ads by Google