0
На рассмотрении

Design patterns book: factory pattern UML and pseudo code confusion

Bruno De angeli 3 года назад обновлен Alexander 3 года назад 1

Hi!

I have a question about the factory pattern example ( GUIFactory ):
- I see in the UML diagram of the GUIFactory the Button and Checkbox as abstract classes

Image 960

but in the pseudocode, I see the implementation as interfaces:

interface Button is
    method paint()
interface Checkbox is
    method paint()

So my question is:

- In UML when we set an "Italic class" it could be an abstract class or interface or is a mistake in the UML diagram?

I also get confused because the Button and Checkbox arrows look like the one of inheritance/generalization ( white arrow with line ) relationship? and not as interface implementation ( arrow with dotted line )

I understand the difference between them, but my confusion is because the center interface of GUIFactory is presented as an interface and implemented in the pseudo-code as an interface

Image 962

interface GUIFactory is
    method createButton():Button
    method createCheckbox():Checkbox
+1
На рассмотрении

Hi!

Thanks for a good question.

Strictly speaking, making the base products interfaces would be the most purist and minimal thing to do, because we are only interested in communicating the fact that the concrete products have a common parent. However, this doesn't mean that you have to specifically declare interfaces for this purpose. If you already have a class hierarchy, using the base class in the creation method result types would do just fine.

Сервис поддержки клиентов работает на платформе UserEcho