This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
First class:1) Product
Subclasses of Parent: 1.1) Cheese - 1.2) ComputerParts - 1.3) Service - 1.4) Fruit
SubSubclasses of Computer parts: 1.2.1) Ram - 1.2.2) Peripheral
Sub Sub Subclasses of Peripheral: 22.214.171.124) Printer - 126.96.36.199) Monitor
I need to code a subclass of a class called GenericOrder and call it ComputerOrder which will take an arbitrary number of only ComputerParts Objects, Peripheral Objects and Service Objects.
BTW my GenericsOrder class is:
I'm very stuck, I'm afraid this is as far as I've gotten:
*** but this is incorrect: i need to be able to take an arbitrary number of different classes of ComputerPart objects, Peripheral objects and Service objects.
There is a lot of controversy about tagging interfaces, but this is how you can do it
Joined: Oct 13, 2005
You can probably also do it with an annotation, but I am not sure how. Anybody else?
Joined: Jun 17, 2011
Thank you for sticking with me. I have posted the class structure here: www.netmatrix.com/classes.jpg
This is where I am at:
This doesn't seen quite right to me. I understand interfaces cannot have any logic (definitions in them) so I need somehow check that only ComputerPart, Peripheral or Service objects are permitted. Did I create the interface correctly or is this what it is supposed to be:
Darryl's solution works, thank you. Could some help me understand why my version of this does not work:
My line "myComputerOrder.add(new ComputerOrder(1));" is wanting an IComputerOrder object. Can someone explain this to me? I really want to understand this. Thank you.
Darryl's solution modifies ComputerPart as an interface (rather than a concrete object as the problem suggests). Guessing from what you are trying to implement (after inferring from other answers), your problem may be around the point where you declare interface (IComputerOrder) and how ComputerPart is defined as concrete class. My guess is that your ComputerPart concrete class doesn't implement IComputerOrder interface.
Can you post the code for IComputerOrder and ComputerPart. I am just guessing so I may be wrong.
SCJP 1.4 90%, SCWCD5 94%, Next SCDJWS--> In Naescent stage. Researching abt exam and material itself.