Customer concept in OOP design patterns?

I read a lot of topics about GoF OOP design patterns, but I'm not sure about the "Client" concept. So what is it? How can we implement this in our application. Thanks!

+4
source share
3 answers

In a gof book, a client is code or a class that uses classes in a template.

for example, from an abstract factory template with motivation:

diagram with client

Consider a user interface toolkit that supports many look-and-feel standards, such as Motif and Presentation Manager. Different views and sensations determine the various manifestations and behavior of widgets, such as scrollbars, windows, and buttons. To be portable according to the look-and-feel standards, an application does not have to hard code its widgets for a particular look and feel. Creating widget instances for widgets throughout the application makes it difficult to change the appearance.

We can solve this problem by defining the abstract class WidgetFactory, which declares an interface for creating each basic type of widget. There is also an abstract class for each type of widget, and specific subclasses implement widgets for specific style standards. The WidgetFactory interface has an operation that returns a new widget object for each abstract widget class. Clients call these operations to obtain widget instances, but clients are not aware of the specific classes that they use. Thus, customers remain independent of the prevailing appearance.

There is a separate subclass of WidgetFactory for each standard style. Each subclass implements operations to create a corresponding widget for appearance. For example, the CreateScrollBar operation in MotifWidgetFactory creates an instance and returns the Motif scroll bar, while the corresponding operation in PMWidgetFactory returns the scroll bar for Presentation Manager. Clients create widgets exclusively through the WidgetFactory interface and do not have knowledge of classes that implement widgets for a specific appearance. In other words, clients must bind to an interface defined by an abstract class, rather than a specific concrete class.

WidgetFactory also provides a dependency between specific widget classes. The Motif scrollbar must be used with the Motif button and Motif text editor, and this restriction is enforced automatically as a result of using MotifWidgetFactory.

+3
source

As a template, a client is an actor that initiates interaction with a server, which is a functional, but usually passive, actor. Acting on behalf of the client, as described in the request, the server performs an action and returns a report in the form of a response.

Thus, the client interface point should make it convenient or possible for arbitrary code to formulate a request and attract the attention of the server. Since the request message can be transmitted over a wide range of media (for example, in another memory space), a hidden mode of transport is usually used, hidden behind this request interface.

It is pretty much long and short as a concept. One of the drawbacks of a very flexible template (which, of course, relates to the client / server) is that you need to go to a specific example, framework or library to speak specifically.

+2
source

A client is another module or class in which the system uses a specific template (all or part of the components build a template)

0
source

All Articles