Reputation: 105227
I have defined an Event class:
Event
and all the following classes inherit from Event:
AEvent BEvent CEvent DEvent
Now, with the info I gather from all these Event classes, I will make a chart. With AEvent and BEvent, I will generate points for that chart, while with CEvent and DEvent I will paint certain regions of the chart.
Now, how should I signal this in my class hierarchy?
Thanks.
Upvotes: 0
Views: 316
Reputation: 40356
I wouldn't think that an Event would have anything to do with drawing. So I would tend to create something like an EventPainter with subclasses PointEventPainter and RegionEventPainter. Some other entity would be responsible for getting the appropriate EventPainter for a given Event.
Upvotes: 2
Reputation: 11297
It really depends on your exact scenario. AEvent, BEvent, RegionEvent, PointEvent are a little vague. ;-)
Option 1 seems to be ok in most cases. However it also sounds a bit like interfaces á la IDrawsRegion
or IDrawsPoint
would be good here. Also I feel that a bit of the Strategy pattern shines through here which you might want to take a look at.
Upvotes: 1
Reputation: 564931
There isn't enough information to know for sure, but it sounds like your first option is the best.
Since AEvent and BEvent are both, in essense, PointEvent subclasses, it makes sense to have a PointEvent class. Same is true with the RegionEvent.
This will help you consolidate shared code, and avoid repeating code unnecessarily.
Upvotes: 1