[Cs3] order of class definitions in the observer discussion

Mikhail Nesterenko mikhail at cs.kent.edu
Wed Nov 6 17:54:50 EST 2019


CS3 students,

This is regarding the question in class regarding the order of class
definitions in the observer pattern example that we discussed in
class:

   http://vega.cs.kent.edu/~mikhail/classes/cs3/Examples/Observer/observer.cpp

The classes are defined in the following order

   Observer 
   Subject 

   ConcreteObserver
   ConcreteSubject

Potentially, this order 

   Observer
   Subject

   ConcreteSubject  // subject first
   ConcreteObserver

would eliminate a few forward references in ConcreteObserver
definition, but then the program would look weird since the order of
definitions of observer and subject are switched from abstract to
concrete.

Potentially, the order may be preserved as follows:

   Subject  // subject first in both abstract and concrete cases
   Observer

   ConcreteSubject  // subject first
   ConcreteObserver

But it looks kind of weird still since (abstract) observer is a
relatively simple class, while (abstract) subject stores a collection
of observers. So observer-first order seems natural.

So, in the end. I decided to leave the order of class definitions as
is. Any comments and suggestions are welcome.

Thanks,
--
Mikhail


More information about the cs3 mailing list