Wednesday 25 September 2013

Where to locate certain functionality - in the object class methods or in the application code? (Object oriented design)

Where to locate certain functionality - in the object class methods or in
the application code? (Object oriented design)

It's been a very long time since I touched object oriented programming, so
I'm a bit rusty and would appreciate your insight.
Given a class, for example CDPlayer, that includes the field
numberOfTracks and currentTrack and the methods getCurrentTrack and
setCurrentTrack, where should I put the functionality to set the current
track to a random track? In a method such as setRandomTrack inside this
class, or in the application code outside this class (e.g.
player1.setCurrentTrack(randomnumbergeneratingcode))?
What are the pros and cons of each of these approaches? Which is easier to
use, change and maintain?
Many thanks!

No comments:

Post a Comment