0%

Being SOLID in Unity n°1 - What does SOLID mean ?

Post title reading SOLID in Unity, What does SOLID mean

Among coding principles the SOLID principles are maybe the most well known. If you ever studied for a software engineer job interview, there is a high chance that you already know about it.
I will try to find the best way I could to apply those principles to a Unity project and share it with you.

So first let’s talk about what SOLID means exactly ?

SOLID definition

SOLID is an acronym for five principles used in object-oriented development. They were first introduced by Robert C.Martin also known as “Uncle Bob” one of the writer of the Agile Manifesto in his paper Design Principles and Design Patterns in 2000.

Those principles are here to help developers create better code that is easier to use and understand and with stronger maintainability.

It is not enough for code to work.

Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship

Let’s dive into theory and what SOLID means :

  • S stands for ‘Single-responsability principle’ : It means that every class or script in our case using Unity, should have only one responsability.
  • O stands for ‘Open-closed principle’ : When writing code you should expect someone else to use your classes, your code should be open for extension but closed for modification.
  • L stands for ‘Liskov substitution principle’ : This principle was first introduced by Barbara Liskov in 1988. The idea behind this principle is that every class could be replaced by another class that extends the one that is replaced.
  • I stands for ‘Interface segregation principle’ : The interfaces classes exposes should only contains what the consumer needs. Interfaces should be as small as possible.
  • D stands for ‘Dependency inversion principle’ : You should only depend on abstractions and not on concrete instance.

How well does it fit in a Unity project ?

I will try to answer this question in upcoming posts by looking at all the five principles and explaining where you could apply them in your Unity projects.

Do not forget that thoses are principles and not strict rules. The best way to use them is to understand them and apply them when you think it makes the most sense.

In the end

Don’t worry if it’s too fuzzy for now, I will try to explain each principle more in depth in later posts as well as explaining how we can use those principles in Unity projects more specifically in scripts.