Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC. The main difference between the two is that one runs the Linux operating System and the other runs the Windows System (of course another difference is that one needs constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?
Answer:Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type.
probably because both a linux and a windows pc can be a workstation and a server and branching the design on the operating system would then introduce redundancy. Also while we might look at a PC as being a Linux or Windows pc in reality either one is just the same old PC and while one has-a Windows installation the other has-a Linux installation on it. Also, at a later date someone might take a PC with Windows on it, reformat and install Linux. If operating system was a field it would be facilitated by change a variable value. If it's an object there's no easy way to do it. [ July 22, 2005: Message edited by: Sergei Iakhnin ]
Originally posted by Sergei Iakhnin: ...while one has-a Windows installation the other has-a Linux installation...
I like that answer. An operating system is not a computer -- it is an attribute of a computer.
(On the other hand, the degree to which this makes sense really depends on the problem you're trying to solve. The model does not always need to parallel the real world.) [ July 22, 2005: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org