Afshin Moazami
Afshin Moazami

Reputation: 2098

Factory Design Pattern with Some Completely Similar Methods

I am using the factory design pattern in Java.
According to this pattern, every classes implement an interface and all its methods in the way that they like.

Now, my question is, assume the situation that there are some methods that are exactly the same and some methods which are not (and should be implemented separately)

In this scenario, can I use Factory design pattern.
If no, how can I benefit from the property of deferring instantiation to subclasses?
If yes, where should I implement the common methods?

Upvotes: 0

Views: 146

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533500

where should I implement the common methods?

In an abstract class which implements your interface. You implement common methods and leave methods which are not.

Upvotes: 3

Related Questions