class diagram for a clock
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Joost_Feyen
Posted On:   Wednesday, November 10, 2004 03:13 AM

Hi

I had to make a class diagram for a clock for school. I made one but my teacher told me it wasn't correct. let me try to explain my model :

I have 3 classes : HourHand, MinuteHand and SecondHand with a parent class Hand (methods : transform, draw, rotate).
those three classes have an composit relation with Form1, I have al my stuff on a form, but that should be the mistake. this Form1-class has a composit relation with my clockFace (methods : draw, drawimage, drawclockface, drawclocknumbers, update rectangle, drawpin)

How can I fix it en leave the Form1-class away?

Re: class diagram for a clock

Posted By:   Anonymous  
Posted On:   Thursday, November 11, 2004 11:16 PM

This is a typical homework question, where the you need to find out what your teacher expected, not what actually would makes sense.

For a real software system, the classes you'd like to have depend on the *behaviour* of the system, and how you can distribute it between objects so that the design is flexible enough to allow cheap modification and reuse of code.

For example, if the system should show a clock to a user on a screen, you could have a Clock, a ClockView and a Timer. The responsibility of the Clock is to do clock arithmetic - to know that a minute has 60 seconds etc. The responsibility of the ClockView would be to show the current time to the user. That way you can exchange the presentation (digital, analog, sound etc.) without having to touch the clock logic in the Clock class. The Timer would tell the clock when another second has passed. Again, you could exchange different implementations without touching the rest of the system (use the system clock, a network time server, whatever). The Timer also allows it to test the other two classes without relying on the real time, by using a Test implementation that you have under full control.

As you can see, I don't have any Hand classes in the above description, because for the system I envisioned, they wouldn't have any behaviour (in fact there would be cases were there aren't any hands). Of course this is just one example for a "clock" system - you could certainly formulate it differently and then you'd need totally different classes. What you probably wouldn't need in either case is a class model that "models the real world".

Telling the above to your teacher probably won't help you (though it might be interesting how he reacts), but I hope it motivates you to take what he teaches with a grain of salt... ;)

About | Sitemap | Contact