It is exactly opposite of software design Patterns. Some the well known anti patterns are the problems which software industry faces. Anti patterns are out comes of following bad practices, over engineering, implementation of design patters without having enough knowledge of patterns or not understanding the context of problem.
Anti patterns are real world experience of understand recurring problems of software industry. It helps to recognize problems and understand the cause of it. They are also a bridge between understanding architectural concepts and its real world implementations.
There are three categories of software anti patterns like:
- Software development anti patterns
- Software architectural anti patterns
- Software Project Management anti patterns
Some of the Development Anti Patterns
1. God Object (Monster Object)
If some object knows too much or does too much, it is called a God object which is opposite to Single responsibility Principle one of the SOLID principal.
If the problem is big, it is very hard or tough to resolve it. So if we divide it into smaller parts of problem, it is easy to solve them. So in software engineering, if we create an object with single responsibility, we should divide one big task into smaller separate responsibility (class) so when any change or problem occurs, we have to change a smaller class and also we have to test only one smaller class after change.
In case of God object, it is very tough to maintain it. It is also very tough to test it. If we change something small of a God object, we have to test the whole object functionality.
- Single class with many attributes & operation
- Controller class with simple data object class
- Lack of Object oriented design
- A migrated legacy design
- Tough to maintain
- Tough to test
- Lost all object oriented advantage
- Too complex to reuse
- Expensive to load
2. Copy and Paste Programming
This is a favorite of any developer including myself. Ctrl + C, Ctrl + V is part of any developer's life. It is good if you are doing it from external sources to boost your development with good understanding of it, but it becomes Anti pattern when you do it with your own code. If you are doing copy and paste of your own code, then it is an Anti pattern.
- Similar code found in an application
- When client changes the requirement, you have to change code at more than 1 place
- Bug found by tester and developer has fixed it, but it reoccurs (because it was not fixed in all the places)
- No code review done by experienced programmer or lead
- It has huge maintenance efforts, If some requirement changed, developer has to change code to many places.
- Developer's lack of knowledge of software development principals like OOPs, SOLID, DRY (Do not Repeat Yourself).
- Lack of forward thinking among developers.
- A "Not Invented Here" syndrome applied to development environment. Meaning development environment does not adopt external tools and employ reinvent the wheel.
- Developers lack of knowledge of new easy technology available.
Whenever you as an developer come across the situation to copy and paste your own code, stop that and find the opportunity to write it with common class or component and make it reusable with loose coupling.
3. Functional Decomposition
In Object oriented environment, If someone writes code in procedural programming way, just decompose main methods into several
methods, only then it becomes Anti Patterns. So instead of writing different classes or design class architecture according to different tasks, if code is just decomposed into
methods only then it is an anti pattern. This is mostly done by an experienced programmer in procedural languages like C and shifted to Object oriented programming language.
- All Class attributes are
private and used in one class
- Degenerated architecture and missed most object oriented architecture
- No use of reusability
- Very tough to do documentation or design class diagram
- Lack of object oriented design understanding
- Lack of architecture enforcement
4. Spaghetti Code
Spaghetti code is a code meaning unstructured code, written by a developer who is less experienced or lacks knowledge of Object oriented programming. Code written like a procedural programming. In this kind of code, the developer himself can't understand his own code after a few days. The code looks like spaghetti.
- Code is not much reusable
- Flow of execution dictated by objects and not the client of the objects
- Minimum relationship exits between objects
- Code is not unit testable. or ends up writing too many integration tests
- No advantage of Object oriented programming
- Very difficult to maintain. so maintenance cost is higher than rewriting new from scratch
- Code written by inexperienced object oriented programming developer
- No design prior to development
- No effective code review
Whenever an experienced developer sees this kind of code, he smells it and finds an opportunity to refactor it.
There are some other anti patterns as well. I will understand them thoroughly and edit this blog.