Should the Observer pattern be renamed?

I always got confused by the Observer pattern until I realised that it is actually a Sender Receiver pattern (and in many other languages it is called a Sender Receiver pattern).

The problem with the name is that an Observer and an Observed in common language have two different roles. Observer tends to be passive, might not know the observed, and the observed don’t know the observer or even that they are being observed: you sit in a cafe, drink your coffee, and observe people around you that you do not know, and they do not know you and are oblivious to your observing. It also kind of implies that one party is doing the observing.

However the “observer” pattern is really a Sender Receiver pattern where both have to be actively registered, and both can be a sender of messages and/or a receiver of messages. It’s most often more akin to a mailing list, and the expectation raised by the “observer” moniker (at least in my case) were confusing - the code simply didn’t conform with the expectations raised by the word “observer”.

So maybe it is a good idea to stop talking about “observer” pattern and start using the term “Sender Receiver” pattern instead?

I think it’s largely a matter of personal preference. I tend to prefer observer and subject but then I’m a scientist at heart and we like messing with subjects :smile:.

1 Like

I’m a Scientist myself (Molecular Biologist), that’s why I prefer exact naming - and “Observer” is just not that (in the same way that not every change over time is evolution, eg growth is DEVELOPMENT, and it drives me nuts when I hear American Scientists talk about Evolution when they mean Development).

What Scientist are you?

One could get into a scrap about the definition of an observer but I feel that observing is an active process. As for my day job, I’m a UK-trained doctor (consultant radiologist) and I would say that I spend a lot of my day observing abnormalities in scans.

Yes, observing is an activity. But you as observer do not interact with what you observe. As soon as you start interacting (talking, modifying, experimenting) you are no longer “just” an observer (but are for example an interviewer or experimenter). Sender (and Receiver) conveys in my opinion much better what happens in the “observer” pattern.

If you are happy with “observer” then stick with it. But if you want to teach the “observer” pattern then I would strongly recommend the alternative naming convention.

the observer is watching the subject

the name strikes me as correct

@npalardy: actually, it isn’t.

The “observer” isn’t doing anything. It isn’t observing. For one thing it has no eyes :wink:

It just sits there, not doing anything, until it receives a message. Then it becomes active.

In actuality the “observer” is a receiver.

To give you an analogy: most people think a vacuum sucks in air. But it doesn’t. There is nobody doing the sucking. It is the air that moves (air molecules speed around at about 180 km/h, constantly bumping into each other) and rushes into the empty space (as there is nothing to bump into). So to say “the vacuum sucks in the air” is a backwards way that hinders understanding, but it is so familiar that even some physics teachers say it.

It’s similar with the “observer” moniker. It’s a backwards way of describing what is happening, and for me it was a massive hindrance in understanding what is a very simple pattern. With the sender receiver moniker I got it immediately (incl that every sender can be a receiver and vice versa).

Furthermore the name “observer” does not tell you what role it plays in the sender receiver pattern. Is it sending something to the observed object? Is it receiving something from the observed object?

Basically it comes down to the fact that in teaching you have to draw on what people already know, and each word you use comes with a certain understanding of what it means. If you use a word differently from it’s common meaning, then you make it harder to understand.

Btw a common fallacy of people is to assume that others associate the same meaning to the words they use. As an experiment ask the people around you what a friend is - I ended up with widely differing definitions, and only my friends agreed with mine.

Exactly. But the “observer” isn’t active. It isn’t doing anything until it receives a message. It isn’t even looking for a message. It’s just reacting to receiving a message. So that activity implied in “observer” is simply not there.

This I agree with.

Only true if you believe you are using the word as it is commonly used :smile:.

which programming rarely does (ie/ programming inheritance and human inheritance by progeny are NOT the same in most ways)

Observer is not “hey I’m watching you and I will react when you change even if you do NOTHING”
While that might be a really cool & useful design to achieve thats not this pattern
The SUBJECT lets all of the things that are interested in its state changes know that one has occurred
Its an incredibly useful pattern and one used the the IDE all over to loosely couple things that do not need to be tightly coupled

Apple uses this pattern all over as well with its notification system
The “receiver” of the notification doesnt care who sent it just that it occurred

Now you are making my point for me.

You are looking at it as a programmer.

But newbies coming to programming do not. For them “observer” has different meanings than for a programmer familiar with the “observer” pattern.

And THAT’S why it is better to call it Sender-Receiver pattern.

Observer is not “hey I’m watching you and I will react when you change even if you do NOTHING”

But that is exactly what “observer” implies to a non-programmer, and what made it unnecessarily hard for me to grasp this simple pattern.

I happen to disagree
Dont rely only on the name to tell you how it works

1 Like

… and I’ll defend your right to disagree.

But you misunderstand me if you think I rely on the name only to tell me how it works.

What I am saying is that the naming is misleading when you are new to the observer pattern. I know it was in my case, and I had my “EUREKA!” moment when I realised that it is called “sender receiver” in another language. With enough time I would have internalised the naming the same way I internalised other naming conventions (think back to the “label” instead of “StaticText” commotion because users had internalised “StaticText” - same difference).

well the original description of the design pattern predates the gang of four book and its always been called “observer”

theres the thing that is being “observed” and any time it changes it lets all the registers “observers” know

there ARE other design patterns that seem similar (ie/ command) but they are slightly different in what they do and how they operate
the “semantic” are different

Personally I’ve not seen this pattern called anything other than Observer - but I’ve not written in every other language possible either :stuck_out_tongue:

"A core concept in Object Orientation is messaging and early conceptualization borrowed much from the Actor Model of computation. Alan Kay, the guy who coined the term Object Oriented and invented one of the first OO languages SmallTalk, has voiced regret at using a term which put the focus on objects instead of on messages, which he considered the stronger idea.

When talking about a message, there’s a natural “sender” and “receiver” of the message. The sender is the object which invokes a method, the receiver is the object whose method is invoked. In Ruby, if one calls a method without explicitly naming an object, that sends the method name and its args as a message to the default receiver self .

In OO, “making a call”, “invoking a method”, and “sending a message” are equivalent concepts. Similarly “being called”, “having one’s method invoked”, and “receiving a message” are equivalent."

I think that might be the difference in our view. I come from a messaging view where When talking about a message, there’s a natural “sender” and “receiver” of the message, while you come from an object based view.

With “Observers” there is no messaging implied (eg you can sit in a cafe and observe the World go by, and if you tell someone “I’m observing you.” then they think you’re a creep :wink:), but the “observer pattern” is all about messaging.

applying normal english semantics to programming - they dont always fit - this is such a case

yes it probably could have had a better name but this is what most people call this pattern
you wont change that at this point
but calling it something else will confuse the heck out of others :slight_smile:

observer is all about “let me know when something about you changes as I’m interested in knowing this” so in that regard the observed object sends all its interested parties a message saying “hey I changed”

applying normal english semantics to programming - they dont always fit - this is such a case

Yup. But “normal english semantics” is where people come from.

yes it probably could have had a better name but this is what most people call this pattern
you wont change that at this point

I agree on that.

but calling it something else will confuse the heck out of others :slight_smile:

I still think putting emphasis on the messaging aspect and using a sender receiver terminology will make it easier to grasp for beginners, and from there you can explain the observer pattern. In my experience people understand better if they understand the structure first and then put the specifics in later.

I might try that in an xDev article :wink: