In a nutshell, generics enable types (classes and interfaces) to be parameters when defining classes, interfaces and methods.
Technically, a constructor in one class could create an object of another class, but unless the other class was a child class of the constructing class, it would not have access to the methods of the constructor's class.
This would make more sense for a "contains" relationship between the classes. In that case, the constructor method could have a parameter specifying the class of a contained object. It could then call the constructor of that class to create the object and save a reference to that object in a field of it's own object-under-construction.
Code in the container class, when operating on the contained object, would, auto-magically, invoke the methods of the contained object's class. However, code in the contained object's class would not have access to the containing class's methods.
In reply to Re^3: Perl OOP
by RonW
in thread Perl OOP
by QueenSvetlana
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |