Oo Puzzle (2)

xiaoxiao2021-03-05  28

Description: Activity represents an activity that may have a one-time reminder (onCealarm) or a periodic reminder (Periodalarm). Alarm can only access Alarm when accessible through Activity, and an ALARM is accessed.

Scenario: The following three lines of code Access the attribute AlarmDatetime in the ALARM base class (Note: Please use the following code to pend it) int ID = 4; activity activity = (activity) Orm.getDomainObjectByid ("Activity", ID); DateTime Start = Activity.Alarm.AlarmDateTime; In the above code, the type of Activity.Alarm may be onCealarm or PERIODALM if it is Periodalarm, how to access the public attribute in Periodalam or PERIDAlarm's unique behavior? If we know the type of Activity.Alarm, you can implement int Interval = ((PERIODALM) Activity.Alarm through DOWNCAST. But we often know the type of the Activity.Alarm instance when you get Activity through an ID. Only by the type of (Activity.Alarm is Periodararm) IF (Activity.Alarm Is Periodararm) {.............} I think there is another way to say more, it is to give all the needs to be Activity. The properties of the Access Periodalarm are encapsulated into a method, which is defined in the base class as an abstract function, except for PeriodAlarm, other subclasses use empty implementation.

Question: (1) I want to know how many types mentioned above, have other ways to access subclass properties? (2) Is it in principle from the OO design, if Activity is directly referenced by ALARM, should only access public attributes and behaviors of the ALARM base class? Shouldn't you access the contents of its inheritance category? (3) DDD mentioned the difference between Entity Object and Value Object, ValueObject can only be accessed via EntityObject, if it is a inherited tree, is it a bad design?

转载请注明原文地址:https://www.9cbs.com/read-34716.html

New Post(0)