Roronoa_Zorro wrote:Unless your assignment specifically required you to use a computer analogy I would use something else, and even then, I'd still use something else first to understand it better.Since OperatingSystem objects aren't composed with other OperatingSystem objects this doesn't really fit the pattern. Now of course you may be able to run several virtual operating systems inside one but that stretches the example too much for my taste. A directory tree may be seen as an example of the composite pattern -- class A can be a Node, different types of files are specializations of a Node (B1, B2, ...) and are not composable (can't put one file inside another), and a Directory (D) is a Composable specialization of a Node -- it can contain other Nodes. [Edit: I see Saish beat me to the file system analogy]
Hello , this is my first time posting and I hope to be doing it in the right section. I have a school assignment that says the following: Identify real or abstract structures that could be modeled by the class diagrams represented below: [http://img704.imageshack.us/img704/3523/diagrams.png]
Upon searching I found out that this is a composite design pattern. I have to implement 2 scenarios for this class system. I was thinking of taking class A (from the uploaded image) to be the Software ( more like a program oriented towards a certain domain like multimedia ), B1,B2 could be an Application/Compiler, and the composite class (D) is an Operating System( because is is usually compiled out of many software (program) pieces) . I want to ask for your opinions on this example because I'm not sure whether this is correct or not. If it isn't could you please give me a real-life example of a correct model ?.
Roronoa_Zorro wrote:Well on Unix, just about everything can be thought of as a file descriptor. Devices, external mounts, symbolic links, etc. Take a look at java.io.File for ideas for more operations.
That's what I'm afraid of doing, because I believe it can get complicated and way past the purpose of the assignment. I was looking for simpler implementation. I thought that the hide method should turn on/off the visibility of the file (directory). I also wondering what other subclasses I could get out of AbstractFile. Also thank you for the method suggestion, indeed I will need them.
Edited by: Roronoa_Zorro on Mar 30, 2010 2:03 PM
Edited by: Roronoa_Zorro on Mar 30, 2010 2:05 PM