unclear use of generic types
what are genric types used for?
are genric types only used for creating type safe collections. cant we just use them as simple type safe classes for exmaple can we use genric types in the following manner
consider the following scenario :
in a particular electronics trading company they send order to suppliers. now the products they deal in are TV,REFERIGERATOR,WASHING MACHINE all provided by different suppliers. i.e. different orders are prepared for each item.
the TV specification is defined by class TV. similarly REFERIGERATOR specifications are defined by class FRIDGE. and WASHING MACHINE by class WASHMACH. but the order for all the three has same details
1. item name
2. code
3. quantity
4. addItem()
5. editOrder()
6. SubmitOrder()
why cant we create a genric class named ORDER and keep passing type parameters for TV,FRIDGE,WASHMACH.
now here we are niether creating any linked list or binary tree or some kind of array list. i mean no collection is used. still using genric class beacuse it makes the work easier.
but is it necessary that generic types are just used for creating type safe collections?
|