SOLID - Principles
Make your codebase great again
S ingle Responsibility
O pen-Closed
L iskov-Substitution
I nterface-Segregation
D ependency-Inversion
S ingle Responsibility
- Defined by Robert C. Martin (Uncle Bob) in his book "Agile Software Development, Principles, Patterns and Practices" in 2002
Definition:
A class should have only one reason to change.
O pen-Closed
- Introduced by Bertrand Meyer (french programmer) in his book 'Object-Oriented Software Construction' in 1988
Definition:
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
- First introduced by Barbara Liskov in a 1987 conference keynote
- Then published by Barbara Liskov and Jeanette Wing in 1994
Definition:
Let q(x) be a property provable about objects x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T
in simple terms:
Child classes should never break the parent class' type definitions.
L iskov-Substitution
- First introduced by Robert C. Martin during a consulting-Job for Xerox
- Problem was, that in a printer-software every Job depended on one Single Class
- Every slight Change resulted in an extensive build-process (> 1hr)
- Solution was to segregate functionality and incapsulate them within separated Interfaces/classes
I nterface-Segregation
- Defined by Robert C. Martin in his book 'Agile Software Development, Principles, Patterns, and Practices'
- Always depend on abstract interfaces instead of implementations
- Classes can use interfaces or implement interfaces
- Allows decoupling, so consumer can handle every implementation of the interface
D ependency-Inversion
Thanks for your time and happy Coding!
Programming - Challange
Implement a Score-System for a turned-based game (like Poker) (The game(s) can be stubbed)
- it should:
- be able to keep track of scores for each user
- handle a variable amount of players
- offer an interface to games with at least:
- addScore
- getScore
- reduceScore
- getResults
- get a Winner for different games (easy rules like highest score wins lowest score wins)
- get a List of all Players and their scores
- keep track of a series of games
- export results as csv
SOLID - Principles
By sd_alt
SOLID - Principles
- 1,043