Getting off and getting on are not synchronized
into one synchronized method.
This is because when persons are getting off,
other person may come to that floor.
In addition, checking get-on flag and letting get-on
are also not synchronized. If there is no one to
get on, this is simple; there is no need to let
get on. But, When the elevator sees the get-on
flag is true and decides to stop,
the person who came while the elevator checked
the get-on flag, should be able to have a chance to
get on the elevator. This is why not the entire code blocks,
but the separate four methods are
synchronized.
Describes BuildingMonitor class.
As the name says, this class is designed to
monitor a Building class. Building
owner converts its building object into one
string by using synchronized method
Building.toString(). Then it passes the string
to this monitor for parsing. The parsed information
could be used for various outputs like tables or
graphics.
IPBuilding is an Interface from Person
to Building. A Person has a reference to
Bulding object that created it, but the reference is
only needed in the two cases: when calling the elevator,
and when telling it has finished its job and should
be deleted. Using IPBuilding rather than Building
hides much information of Building 's from the Person.
IPBuilding :
PersonÀÌ °¡Áö°í ÀÖ´Â Building¿¡ ´ëÇÑ
referenceÀÌ´Ù. ¿¤¸®º£ÀÌÅ͸¦ ºÎ¸£´Â °Í°ú ¸®½ºÆ®¿¡¼ÀÇ »èÁ¦ ¿ä±¸¸¸À»
ÇÒ ¼ö ÀÖ´Ù. À̸§ÀÌ ±×·¸°Ô ¸¶À½¿¡ µéÁö´Â ¾ÊÁö¸¸ ¾î·µç
Interface, from Person to Building ÀÇ ¾àÀÚ·Î Áö¾ú´Ù.