The skinny is I have:
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: 188.8.131.52) Printer - 184.108.40.206) 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:
My question is: is this a case of Tuples? And, if so, how does one force the tuple to be of the desired objects ComputerParts object, Peripheral object and Service object?
Well, Java doesn't really have tuples, so no, I don't think it's a case of tuples. A few Java libraries might use the concept of tuples, but I don't think that has anything to do with your question. Is there someplace you've seen discussion of tuples in Java that might lead you to think they exist, or that you should use them here?
Joined: Jun 17, 2011
Thank you for your reply!
I only suggested tuples because of the requirement of my subclass needing to take an arbitrary number of different classes of ComputerParts objects, Peripheral objects and Service objects. I thought this was an opportunity to use 3 unknown types ... I think I was wrong.
Generics is new to me but here is where I am:
The *** this is wrong is because somehow I need to take an arbitrary number of different classes of ComputerParts objects, Peripheral objects and Service objects but this just takes my T type. I don't know how to take the arbitrary number part.
I really appreciate you reading my post! Thank you,
Joined: Mar 05, 2008
Kiley smith wrote: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.
Aren't all Peripheral Objects already ComputerParts? So "an arbitrary number of only ComputerParts Objects, Peripheral Objects and Service Objects" is equivalent to "an arbitrary number of only ComputerParts Objects and Service Objects", isn't it?
I assume this is homework. It's hard for me to imagine what your instructor is trying to get you to do here. Is it possible that a ComputerOrder could consist of two parts: a GenericOrder<ComputerPart> and a GenericOrder<Service>? It's difficult to see how you could subclass a single GenericOrder to accomplish your requirements. But perhaps you can subclass two different GenericOrders, and then use composition rather than inheritance to put them together into one class.
Joined: Jun 17, 2011
Yes, this is a course but the material has been so poorly written it's difficult to deduce what the expectations are. I see what you are saying about composition. Perhaps that's correct. The full reading is:
"Design and implement a subclass of GenericOrder called ComputerOrder that takes an arbitrary number of different classes of ComputerPart objects, Peripheral objects, and Service Objects. Implement as many methods as neccessary."
I know a list/listarray requires the same type of "type" added to it so I can't quite see how I can add unlimited differently typed objects. I tried creating one object and maybe then insert unlimited amounts of that object into a list ... but now I'm getting myself confused.