Design pattern Observer applied to events

5

I'm studying the design patterns and I'm trying to apply a real situation to them.

And an example I made was in the event scenario:

In this scenario every event has participants to register.

So, I have implemented the Observer standard, every time the event date changes, it notifies its participants by sending an email. Is not the form I implemented the case the design pattern Observer could be applied in this case?

    
asked by anonymous 24.12.2014 / 11:07

1 answer

4

The general understanding is this. Nothing prevents you from doing this. But the Observer pattern is a mechanism and not a business rule like you used. Showing a code would give you a better idea.

In fact the Observer pattern implements just events, but not this type of event you're talking about, not social events but computer events.

In the way you created, who are the subscribers? Real people you have no control at all? This does not seem to me to be the default Observer. In this pattern subscribers are often other parts of the application that need to be notified. In general, it is a design pattern created for object-oriented use.

Examples:

  • A file has been modified in the file system
  • A price property has been modified in a product class
  • A click was clicked
  • Received a network information
  • A visual object of the game encountered another object (hit the target)
  • An update to the database occurred

If we can transport the Observer concept from the computer out of it I do not know. What you are doing is something like the defined pattern but it seems to me a variant that does not fit the formal definition of the pattern. It looks more like an observer-like .

You can use whatever logic you want to achieve your goal. What I can say is that if you are worried whether you are implementing a design pattern or not, you are in the wrong concern.

Design patterns depend on implementation, you can achieve your goal in other ways (probably worse) where a design pattern would fit.

Source: Wikipedia

In this diagram, who are your notify() ? The emails of the participants as you called? Sounds strange to me. I think the default was not created for this.

In the background what does it matter whether you are using the pattern or not? Is your implementation doing everything it should do properly and efficiently?

    
24.12.2014 / 12:26