Design Observer applied to events

Asked

Viewed 368 times

6

I’m studying design standards and I’m trying to apply a real situation to them.

And one example I did was on the event stage:

In this scenario every event has participants to register.

So, for that, I implemented the standard Observer, every time the event date changes, it notifies its attendees by sending an email. The way I implemented it does not come to the case, the Pattern design Observer could be applied in that case?

  • You have the code you created?

1 answer

5


The general understanding is this. Nothing stops you from doing this. But the Observer standard is a mechanism and not a business rule as you used it. If I showed you a code, I could do a better job.

In fact the Observer standard implements precisely events, but not this type of event you are talking about, not social events but computer events.

The way you created it, who are the subscribers? Real people that you don’t have any control over? That doesn’t seem to me to be the Observer standard. In this pattern subscribers are usually other parts of the application that need to be notified. Generally speaking 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 has been given on button
  • Received an information from the network
  • A visual object of the game met another object (hit the target)
  • A database update occurred

If we can transport the Observer concept from the computer out of it I don’t know. What you are doing is something similar to the defined pattern but it seems to me a variant that does not match the formal definition of the pattern. Sounds more like a Observer-like.

You can use whatever logic you want to achieve your goal. What I can tell you is that if you’re worried about whether you’re implementing a design standard or not, you have the wrong concern.

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

Diagrama Observer

Source: Wikipedia

In this diagram who are yours notify()? The attendees' emails as you called them? It seems strange to me. I think the pattern was not created for this.

Deep down, what does it matter if you’re using the standard or not? Your implementation is doing everything it should do correctly and efficiently?

  • notify will send an email to each Observer, who in this case is the participant, of the Participant class. Wouldn’t that be the Observer? Plus, thank you very much. I did it using the intention, but I really shouldn’t be using the pattern. Like, you give this example "A price property has been modified in a product class". Wouldn’t that be the same logic? When the date of the event is changed, it notifies the Observers?

  • Without seeing the code it is difficult to evaluate accurately. If the answer was useful you can vote for it and accept it as well if you think it served you. See the [tour].

  • I am without the project here. But I did following the tutorial below. What do you think of the approach of this site? http://blog.camilolopes.com.br/serie-designpattern-observer/ On the website the Observer is the panel, in my case, the participant with the e-mail attribute. And there in the notification(update) method of the Panel class, he would send an email. So? What do you think of this approach?

  • Then everything seems ok, but I don’t know how you implemented it. You put the tags Java and C#. In Java I would do one way, in C# in do another.

  • The implementation is the same. Only in this case the Panel has a name. In my case it is the Participant, the "person". And that person has a name and email. And in the notification part I use a command to email the participant, which will be this.Email, since I’m in the participant’s class. Do you understand? And then you’re really right?

  • It must be, but I don’t know, it’s one thing to describe, it’s another to do.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.