This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Generics & and tuples = panic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Generics & and tuples = panic

Kiley smith
Greenhorn

Joined: Jun 17, 2011
Posts: 27
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

Joined: Jun 17, 2011
Posts: 27
anyone?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3016
    
  10
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

Joined: Jun 17, 2011
Posts: 27
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

Joined: Mar 05, 2008
Posts: 3016
    
  10
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

Joined: Jun 17, 2011
Posts: 27
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

Joined: Oct 27, 2005
Posts: 19697
    
  20

Kiley smith wrote:anyone?

PatienceIsAVirtue.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Continued here.
 
GeeCON Prague 2014
 
subject: Generics & and tuples = panic