mardi 15 juin 2021

Clean way of using subclass and superclass pojo together in java [duplicate]

I have two classes say, class A and class B extends A. I need to call a method func(List<A> list). In the parameter list i should be able to pass a list which can contain objects of class A and class B. Now i need to process them separately based on the instance type.

The class B is a newly introduced class and class A and func existed from before. I am wondering if there is a clean way to process new subtype of class A inside func, or is there any design pattern that i can use here.

Aucun commentaire:

Enregistrer un commentaire