Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

Generics & and tuples = panic

 
Kiley smith
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Kiley smith
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Report post to moderator
anyone?
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Report post to moderator
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?
 
Kiley smith
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Kiley smith
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Kiley smith wrote:anyone?

PatienceIsAVirtue.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Continued here.
 
    Bookmark Topic Watch Topic
  • New Topic