Design Patterns Flashcards

1
Q

Observer

A

The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Publish Subscribe Design Pattern

A

Publish Subscribe is a messaging pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers, but instead categorize published messages into classes without knowledge of which subscribers, if any, there may be. Similarly, subscribers express interest in one or more classes and only receive messages that are of interest, without knowledge of which publishers, if any, there are.
So how they communicate?
There another component named message broker (or “event bus”) which is known by both publisher and subscriber. The publisher will send the message to the message broker and the message broker will filtering and broadcasting the message to the right subscriber.

In other words, pub-sub is a pattern used to communicate messages between different system components without these components knowing anything about each other’s identity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

should u use pub/sub? why?

A

Thanks to its power to reduce coupling, the pub-sub design pattern can be combined with single responsibility service objects (SRSOs) to help encapsulate the business logic, and forbid the business logic from creeping into either the models or the controllers. This keeps the code base clean, readable, maintainable and scalable.

By decomposing the fat models and controllers, and having a lot of SRSOs, testing of the code base becomes a much, much easier process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly