It is said开发者_StackOverflow here http://msdn.microsoft.com/en-us/library/ee817669.aspx#observerpattern_topic3a
This permits a subject to notify a potentially infinite number of observers of state changes, rather than just one.
Why can't I just use
list<Observer>
in the subject class instead of delegating to a container ?
Your list<Observer>
collection is the container that the article refers to. It is an implementation detail whether you chose a list, a map, a set, etc. to hold the set of Observer
s. It really is up to you what to use. The pattern won't change depending on the type of container used.
Your List data structure is a container :)
That sentence is simply distinguishing between maintaining a List<Observer>
data structure (for example) and a single Observer reference.
EDIT: Looks like I was beaten to the punch
精彩评论