SOLID for Unity Cheat Sheet by _Gekko
A bunch of notes taken from Unite Austin 2017 - S.O.L.I.D. Unity
programming solid unity unity3d game-development
Single Responsability Principle
Open Closed Principle
Liskov's Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Keep everything (non-programmers) designer friendly when needed.
If your code is too tough to test, it probably means that's not SOLID.
1. Dependency Inversion Principle
Using classes with shared logic but different features...
Use polymorphism instead of hard references, through interfaces or abstract classes.
In Unity Editor
Use Abstract classes or Scriptable Objects if you want something in the inspector (since interfaces aren't supported).
2. Interface Segregation Principle
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 Editor
The Inspector doesn't support interfaces, but you can use them for internal methods or third party logic.
3. Single Responsability Principle
That 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.
Prefer tiny components.
4. Open/Closed Principle
New features broke old ones
Classes open for extension, but close for modification.
Use abstracts to extends features and define how it'll works.
5. Liskov's Substutition Principle
Extending the classes broke 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.
Download the SOLID for Unity Cheat Sheet
Your Download Will Begin Automatically in 5 Seconds.