12/8/2023 0 Comments Architect definition bridges![]() Note that we’re not talking about interfaces or abstract classes from your programming language. It should delegate the work to the implementation layer (also called platform). This layer isn’t supposed to do any real work on its own. Having read the simple example with shapes and colors, let’s decipher the meaning behind the GoF book’s scary words.Ībstraction (also called interface) is a high-level control layer for some entity. In my opinion, the terms sound too academic and make the pattern seem more complicated than it really is. ![]() introduces the terms Abstraction and Implementation as part of the Bridge definition. The GoF book “Gang of Four” is a nickname given to the four authors of the original book about design patterns: Design Patterns: Elements of Reusable Object-Oriented Software. From now on, adding new colors won’t require changing the shape hierarchy, and vice versa. That reference will act as a bridge between the Shape and Color classes. Now the shape can delegate any color-related work to the linked color object. The Shape class then gets a reference field pointing to one of the color objects. You can prevent the explosion of a class hierarchy by transforming it into several related hierarchies.įollowing this approach, we can extract the color-related code into its own class with two subclasses: Red and Blue. What this means is that you extract one of the dimensions into a separate class hierarchy, so that the original classes will reference an object of the new hierarchy, instead of having all of its state and behaviors within one class. The Bridge pattern attempts to solve this problem by switching from inheritance to the object composition. That’s a very common issue with class inheritance. This problem occurs because we’re trying to extend the shape classes in two independent dimensions: by form and by color.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |