We have already seen SOLID Principles and also few additional design principles and best practices. Let us also see few things that should be avoided in your design. Again, most of these may be indirectly based in the SOLID Principles.
Things to avoid in your design includes, but are not limited to:
-
Run-Time Type Identification (RTTI)
-
Design that require you to check for the actual type of the reference object should be avoided (e.g. if(type(something) = something, do something).
-
-
Cyclomatic complexity (CC)
-
It directly measures the number of linearly independent paths through a program's source code (e.g. the number of if-else-if statements in a function).
-
Note that for every path you need to add at least one additional test case to your unit test cases.
-
As a good practice, we should avoid this as much as possible or limit this to less than 10.
-
-
Swiss knife syndrome
-
‘Swiss Army Knife’ is often used to describe a collection of useful items or tools that are able to perform well in multiple scenarios.
-
The more complex a piece of code or software gets, the less value it provides, and it will be more difficult to maintain.
-
An example is the usual util class. This is the opposite of SRP.
-
-
Lookup
-
Only use as a last resort as in the case of caching.
-
-
Bidirectional coupling and cyclic coupling
-
Create maintenance nightmares
-
-
God class
-
A class that does everything should be avoided.
-
God class will need a God Man, who is the only person who can understand and modify that class.
-
-
Downcast
-
Abandon downcast
-
References:
Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra
- heartin's blog
- Log in or register to post comments
Recent comments