Classtest CAM
Classtest CAM
Design pattern
For the ecommerce Eboutique website, I used the decorator design pattern on
displaying the product price discount. The idea is to decorate the product price with
discount decorators dynamically without affecting the product object.
For example,
2. Open/Closed Principle: The Decorator pattern follows the Open/Closed
Principle, which states that software entities (classes, modules, functions)
should be open for extension but closed for modification. This means you can
introduce new discount types (decorators) without changing the existing
codebase, reducing the risk of introducing bugs in already working code. For
example, the DiscountDecorator class is an abstract class and required
concrete discount implementation classes such as SummerDiscount
extending it and this makes the application open to extension.
4. Flexibility: The Decorator pattern offers a high degree of flexibility. You can
mix and match different decorators to achieve various combinations of
discounts. For instance, you could apply a percentage discount, a fixed
amount discount, or even a combination of both to a single product display.
9. Avoids Class Explosion: Without the Decorator pattern, you might end up with
many classes if you create separate classes for every possible combination of
discounts. Decorators allow you to add features in a more granular and
manageable way.
Builder Pattern
Maintainability: Changes in the way products are constructed can be localized to the
builder class, reducing the impact of modifications on the rest of the codebase.
Therefore, the use of the Decorator and Builder design patterns enhances the
application's design by promoting modular, reusable, and maintainable code. These
patterns allow you to add new features, discounts, or product attributes with minimal
impact on existing code, making your application more flexible and adaptable to
future changes.