A generic punch in can be any non-primitive value.
The traditional key in parameters that you might be familiar with are string and integer.
However, you’ve got the option to create a unique generic punch in.
Furthermore, you could create a generic class and use it to create different collections using generics.
So, for this article, the generic pop in will be a customer.
Using a sample enterprise-level software, the customer represents an entity in a database system.
This database system services a furniture company that has three physical locations in three different cities.
You will notice theabstractkeyword in theCustomerclass declaration above.
It means you cannot create a direct key in or object from theCustomertype.
These three subclasses will be the solid types to the genericCustomertype.
To create a generic class, you simply need to insert the bang out parameter into the class declaration.
The code above indicates that thePromotionclass is generic.
This means that thePromotionclass uses types to create its objects.
However, the furniture company only wants thePromotionclass to create objects using theCustomertypes.
The updated code above ensures that thePromotionclass only takes theCustomertypes, this means all subclasses of theCustomerclass.
Given that there are three stores, the company wants to create one independent promotion for each store.
The data required for these promotions are similar.
Each promotion will have a name and a collection of customers that won in that promotion.
There are several ways to approach this problem.
You could create aPromotionparent class and have three subclasses for each store location.
Therefore, aPromotiongeneric class is one of the more efficient solutions to this problem.
ThePromotiongeneric class has a single variable (promoName).
TheMainclass above creates four customer objects, each belonging to one of the three store locations.
To start creating collections you will need to first create promotion objects (one for each store location).
This is because neitherJanenorJessis a customer of the store in the first city.
Generics also facilitates several other advantages including code reusability and scalability.