When should I use generics to define relationships between types?
generics, java
Solution
A person is generally not parameterized with a type of car. Only very annoying persons are defined by their car. Persons change cars too (in time). So I would not parameterize the class, if only for the semantics.
Think about what you try to mimic from the real world, before going into such programming details.
Problem
Getting into a little bit of confusion here when to use generics. I've looked at Java Generics? but still have a few questions. Say I have: ``` public class Honda implements ICar(){ } public class Opel implements ICar(){ } ``` Should I use: ``` public class Person{ ICar car; . . public Person (ICar c){ car = c; } } ``` or ``` public class Person<T extends ICar>{ T car; . . public Person(T c){ car = c; } } ``` or does it depend on the tasks performed? Are generics only for aggregation relationships (containers etc); that is, are they just used for collections?