Today I practised SOLID by making Kata. I choosed very popular Kata: The String calculator. Do you know what Kata is?
Kata is a basic motion. It is a Japanese word, which describe specific motion sequence (fight moves). Regular Kata repetitions allow you to practice to perfection in your chosen technique. In programming, Kata describes sequence of tasks to do and be a better programmer. Kata is programming and solving the problem step by step, practicing for example TDD. The sequence is as follows:
- Read instruction (business requirement).
- Write a test, to check the code (confirmation of meeting business requirements).
- Write code, to pass the test (solution).
- Improve the code (refactoring).
SOLID — reminder
SOLID principles are basic rules of object-oriented programming. You should not only know them but also practice and use them at work. At first, I remind you of SOLID principles, and then I show you some exercises.
Single responsibility principle
Every class should have only one responsibility (every class should have only one reason to change) — one purpose of existence.
All classes should be open for enlargement and closed for modifications.
Liskov substitution principle
The application should work correctly when we put in the base class place every derived class.
Interface segregation principle
Many small and dedicated interfaces are better than few and general.
Dependency inversion principle
High-level modules should not depend on low-level modules, but the dependence should result from abstraction.
Today I was practising SOLID with kata: https://osherove.com/tdd-kata-1/. I was using VisualStudio 2019, and running unit tests written in Microsoft.VisualStudio.TestTools.UnitTesting. To run unit tests, I was using shortcut: Ctrl+ R, A.
All posts from mini project: Learn SOLID and OOP principles:
- SOLID exercises
- S like Single responsibility principle
- SOLID exercises — Kata
- O as Open-closed principle
- L jak Liskov Substitution Principle
- Interface segregation principle
- KISS — Keep it simple, stupid
- DRY — Don’t repeat yourself
- Dependency inversion principle
- SLAP — Single Level of Abstraction Principle
- Composition Over Inheritance
- Encapsulate what changes
- Lod — Law of Demeter
- ES as Exercises of Single responsibility principle
- EO as Exercises of Open/closed principle
- EL as Exercises of Liskov Substitution Principle
- EI as Eexrcises of Interface segregation principle
- ES as Exercises of Dependency Inversion Principle
- Object-oriented programming
- OOP — Object-Oriented Programming — Advice
- OOP — Object Oriented Programming