3 Anti-pattern: excessive frameworks
Writing much of the code on top of complex frameworks instead of using layered design is an anti-pattern.
This is because:
- Frameworks tend to increase the size of programs ("code bloat")
- The complexity of framework APIs tends to increase overall development time due to the need to spend additional time learning to use the framework
- The inversion of control means you give up control
- Frameworks tend to have complex configuration
- It's difficult to design a framework well
- Frameworks tend to have lower performance, for example there is usually more dynamic polymorphism and less inlining
- Code written for a framework is difficult to test (with automated tests)
- Frameworks tend to be monolithic, in contrast to layered design which emphasises many independent modules
- It's essentially an example of the more is less anti-pattern
Many software developers have an unfortunate tendency to write large applications directly on top of User Interface frameworks. A failure to separate User Interface code from the domain data structures and algorithms is an example of the excessive frameworks anti-pattern.
Similarly many software developers write applications on top of messaging frameworks.
Excessive use of dynamic polymorphism increases abstraction in a bad way, it hurts readability of the code.
Rather than have function names which actually say what they do, there is a tendency to have generic names
like OnMessage or OnKeyDown.
For example, it's probably a good idea for a function which might start a world war to have a descriptive
name such as LaunchNuclearMissile rather that lurk in a function named
OnButtonPressed.
The Single responsibility principle (SRP) suggests a message handler should only be responsible for receving the message and making a call on some other object which executes some function. This means the message handler has very little code, it's just an thin adapter. In that case most of the code is written in a layered manner, respects the SRP, and uses descriptive names for functions, rather than being written on top of some framework.