The minimal Observer design pattern example had only a single state. You might think that adding additional states may be complicated, but you'll see that it's very easy. One of the key features about design patterns is that they're flexible, and adding states illustrates this flexibility.
Another issue that can be important in some applications using the Observer pattern is getting to know the observers. In the minimal example in the previous section, the observers were identified by their array index, which changes when observers are removed. However, using a property to identify observers is quite simple as well.
To understand multiple states, just imagine a daily newspaper that has several different sections. For example, an abbreviated list might include the following topic areas that regularly need to be changed:
All these areas can be represented as
String data, but for the sake of type variety, we will make
Number type. In the minimalist
example, the initial placement of the state property is in the
update() parameter. To have additional property
states, all we need to do is add more properties. So, in the Observer interface,
we'd just need to change the
function to the following:
function update(news:String,sports:String,stocks:Number,entertainment: String):void;
That was easy. As you can see, different data types are not problematic at all.
Next, the concrete subject ...