Forums Register Login

Generics & and tuples = panic

+Pie Number of slices to send: Send
Hi everyone,

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: 1.2.2.1) Printer - 1.2.2.2) 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?



Many thanks,
K
+Pie Number of slices to send: Send
anyone?
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Hi Mike,

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,
Kiley
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Hi Mike,

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.
+Pie Number of slices to send: Send
 

Kiley smith wrote:anyone?


PatienceIsAVirtue.
+Pie Number of slices to send: Send
Continued here.
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


Reply locked
This thread has been viewed 2010 times.
Similar Threads
Swapping objects between two arraylists
JComboBox display issue when changing models
next() cannot override next() in my abstract list.
List -in collections
Extending Generics to Subclasses
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:47:55.