Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generics & and tuples = panic

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
anyone?
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Kiley smith wrote:anyone?


PatienceIsAVirtue.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Continued here.
 
    Bookmark Topic Watch Topic
  • New Topic