title | category | layout | tags | prism_languages | ||
---|---|---|---|---|---|---|
SOLID (object-oriented design) |
Design Patterns |
2017/sheet |
|
|
(S) SRP
| Single Responsability Principle
(O) OCP
| Open Closed Principle
(L) LSP
| Liskov's Substitution Principle
(I) ISP
| Interface Segregation Principle
(D) DIP
| Dependency Inversion Principle
The 1% error prone classes with 99% of the total game logic.
Split the game logic into small classes with simple code. One class does only one thing and has only one reason to failure.
In Unity
Prefer tiny components.
New features break old ones. Classes open for extension, but close for modification. Use abstracts to extends features and define how they work.
Extending the classes break them
If two different types have the same base type, they should both works for all members that use the base type. Trust the type as the base type.
Large interfaces are time expensive
Break them into small, focused ones. Use only one member or member purpose per interface. Keep in mind that one class can implement many interfaces.
In Unity
The Inspector doesn't support interfaces, but you can use them for internal methods or third party logic.
Using classes with shared logic but different features...
Use polymorphism instead of hard references, through interfaces or abstract classes.
In Unity
Use Abstract classes or Scriptable Objects if you want something in the inspector (since interfaces aren't supported).