Java – AbstractFactory and bridge mode

I just learned bridge pattern and its intention: remove an abstraction from the implementation so that the two can change independently

But why can't an AbstractFactory do the same thing?

I know that an AbstractFactory can create a specific bridge, but my problem involves using AbstractFactory instead of a bridge to decouple abstraction and implementation

Can you explain the real difference between AbstractFactory and bridge pattern?

Solution

First of all, the bridge model I read is more when the classroom is different from its role The class itself can be considered as abstract implementation and class behavior

On the other hand, the abstract factory provides an interface for creating related or dependent object groups without specifying their specific classes; Their implementation problems

So I want to conclude that you are comparing apples and oranges. Maybe that's where the confusion comes from They are trying to solve different problems

To me, operations mean methods in Java, so operations are defined or declared abstractly, but implemented in the class itself So yes, the abstraction just declares what the operation can do, but the actual implementation is done in the class In addition, the abstract factory is also correct

I guess part of the definition of a bridge is that it can have a set of abstractions different from an abstraction

Design patterns use word abstraction to refer to classes that depend on a set of abstract operations, in which several implementations of the set of abstract operations are possible

For more information, see these links:

Using Abstractions and the Bridge Pattern in Java

Wikipedia: Bridge_ Pattern

Bridge Pattern in Java

The Bridge Pattern Design Pattern

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>