dimanche 29 avril 2018

Design pattern for calling different functions for different instances

I have a java code like this-

Sample obj;
if(obj instanceOf Class1) 
{
    method1(obj);
} else if(obj instanceOf Class2) 
{
    method2(obj);
} else if(obj instanceOf Class3) 
{
    method3(obj);
}

I want to write the logic of method1, mehtod2 and method3 in a different class. Is there a design pattern for that. I am using spring MVC.

Aucun commentaire:

Enregistrer un commentaire