|Lesson 6||Limitations of design patterns |
|Objective||Decide whether to alter the Observer pattern. |
Limitations of Design Patterns
- Design patterns build on the foundations laid by a solid analysis of software development.
You will not find a pattern that solves every problem you encounter.
- It is valuable to remember that every pattern has its consequences.
- Design patterns are not part of a programming languages syntax.
Some problems are simply intractable and unmanageable. Other problems may have a solution, but there are no widely known patterns to solve the challenge at hand. Indeed, this may be an opportunity for you to make a mental note by documenting a pattern you invent, discover or document as you synthesize existing patterns to create new patterns.
Limitations of Design Patterns in Software Engineering
What are the limitations of design patterns within the realm of software engineering?
- Not Universal Solutions: Design patterns address recurring problems in software design. However, they aren't universally applicable. Implementing a design pattern without a genuine need can introduce unnecessary complexity and overhead.
- Technology and Paradigm Shifts: While patterns abstract from specific technologies, they don't always adapt seamlessly to new technological advancements or programming paradigms. Over-reliance on established patterns may hinder the adoption of innovative techniques or solutions.
- Learning Overhead: There exists a broad range of design patterns, each with its specific intent and nuances. Understanding them fully requires a significant investment of time and effort, which can be a deterrent for developers new to the domain.
- Performance Trade-offs: Certain patterns, particularly those introducing additional layers of abstraction, can impact system performance. The Proxy or Decorator patterns, for instance, while providing flexibility, may introduce latency in system operations.
- Inflexible in Changing Contexts: Once a particular design pattern is deeply embedded into a system, evolving or changing the system's design can become challenging without a comprehensive refactoring, which can be costly and time-consuming.
- Misuse and Overuse: Due to their popularity and perceived benefits, there's a tendency to overuse or misuse patterns. This can lead to over-engineered solutions where simpler designs might suffice.
- Variability in Implementation: The conceptual nature of design patterns means they aren't tied to specific implementations. While this provides flexibility, it can also lead to variations in how patterns are implemented, potentially causing inconsistencies in software projects.
- Potential for Stifling Innovation: An overemphasis on established patterns can curb the inclination to think outside the box. Relying solely on known patterns might limit the exploration of novel solutions to unique problems.
While design patterns offer invaluable insights and solutions to common software design challenges, they are not without limitations. Prudent software engineering requires recognizing these constraints and employing design patterns judiciously, ensuring that the chosen patterns align with the specific needs and context of the project at hand.
A Pattern's Consequences
For instance, most pattern approaches, especially ones that rely on polymorphism, are slightly slower than an equivalent solution that does not encourage reuse. However, this may be trivial compared to the time saved using the pattern. Each design decision must be considered individually. Only use a design pattern if its benefits outweigh its costs.
Avoid getting locked into Specific Interpretations of Patterns
They are ways to think about and organize solutions to common problems.
They are not written in stone. If a pattern is not working for you, you can change the pattern to make it work.
- Architectural patterns consist of: pipes, repository, event, client-server, proxy
- modularity class patterns: iterator, visitor, bridge, strategy, observer
- synchronization: events, locks, monitors, leases
- useful techniques: singleton, object pool
Architectural patterns represent functional relationships between components.
Types of Patterns
Behavioral patterns consist of the following 3 areas.
- algorithms and processing techniques
- resource creation/management techniques
- communication and synchronization techniques
Architecture: Pipes and Filters
- Application stream data processing and transformation
- Approach: pipeline of generators, transformers, filters
- independence of the processing elements
- power of composing independent elements
- reusability/replaceability of elements
- Limitations: no feedback between stages
Observer Class - Exercise