Whats the relationship between the LIGHT and REMOTE class? (interms of association or composition)
I dont think Remote Has-A a light is valid relationship.... But in the real-world Light Has-A Remote seems to be correct for me.... Whats your opinion?
Software Engg
Akhash
Agree. Since the other posting was on somebody else's thread, that is regarded as hi-jacking the old thread. I have obscured the other post so you won't get any replies there.Bear Bibeault wrote:Please do not post the same question more than once.

It was better to create a new thread for a new question.
I think you are correct: remote has-a light. Whether that has anything to do with the real world is not important. Your code creates a situation where a remote has a light, and if the real world is different, well that's the real world's problem

What you are thinking is absolutely correct, and it should be that way and it can.
I don't think switchOn() or switchOff() is the behavior of light, it is the function of a remote. The light simply responds to these commands. You could think on those lines...

Campbell Ritchie wrote: ..and if the real world is different, well that's the real world's problem.
![]()
Javattidude!

Don't walk as if you rule the world, walk as if you don't care who rules it...
you can even make a class Animal which has all the birds
but i can see that your code has class remote which call light class methods to check whether the button is pressed or not.
SCJP6.0,My blog Ranchers from Delhi
Abimaran Kugathasan wrote:
Akhash Ramamurthy wrote:
There is a syntax error in the coding. Nobody noticed?![]()
Good Catch..Great..

SCJP6.0,My blog Ranchers from Delhi
Ninad Kuchekar wrote:Hi Akhash,
What you are thinking is absolutely correct, and it should be that way and it can.
I don't think switchOn() or switchOff() is the behavior of light, it is the function of a remote. The light simply responds to these commands. You could think on those lines...![]()
Campbell Ritchie wrote: ..and if the real world is different, well that's the real world's problem.
![]()
Javattidude!![]()
I actually tried to create a loosely coupled design. That made me think ON and OFF is something that the light should do and not the remote... Later if the requirement changes and if I introduce a dimmer behavior for the light I can still use the same toggleSwitchPressed() function in the Remote to dim or brighten the light...
Software Engg
Akhash
So something like:
Now,
Now use this Interface reference in your class Remote. You could also add some more Transponders by implementing this interface. Now your Remote "has-a" Transponder.
There is much more you could do to the above code to make it close to real world. You could add another abstract level between the interface and your class. But this one is simple enough.

Don't walk as if you rule the world, walk as if you don't care who rules it...
Whats the relationship between the Elevator class and the Button class ?
I kind of confused since Elevator has Button members and vice versa....
I didnt use a IDE to type my code.... so if any typos please dont pounce on me... :-)
Software Engg
Akhash
I am not an avid UML user, but isn't "has-a" relationship denoted like this...
Remote<--Light...?
The arrow should point the other way around. As far as straight line and broken arrow, I know straight line has stronger relationship than dashes. (maybe this is a C++ thing).
Gary
star chaser..

See where your hand is? Not there. It's next to this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
|