I have used Factory pattern where I have multiple classes which does similar sort of work, but I don't want client to worry about class instantiating and return types. So Instantiate the necessary class dynamically depending on input and pass the values. These classes have similar methods but does slightly different work and these classes inherit the same common interface. Is this the correct way or can I improve it further?
It is perfectly legitimate to use a factory pattern to instantiate different classes that implement a common interface. The classes themselves could be derived from a variety of sources and could even offer a range of other services. The key point is that as long as the
WhatIWantToDoFactory returns an object that implements the
IWhatIWantToDo interface its job is done.
This kind of capability is particularly useful in assembling structures using Dependency Injection/IOC principles.
Having said all that, this is question and my answer to it border on being opinion-based, and are only a marginally good fit for this site. IMHO.