开发者

Why should I use a container for storing observers?

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 Observers. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜