I have a simple class called Link
that contains some properties, and use different classes for creating different types of links.
My code looks like this:
class Link {
String reference, label, target, ...
}
interface LinkFactory {
Link createLink(Person person)
}
class EditLinkFactory implements LinkFactory {
Link createLink(Person person) {
// complex "create edit link" logic goes here
}
}
class DeleteLinkFactory implements LinkFactory {
Link createLink(Person person) {
// complex "create delete link" logic goes here
}
}
I have appended the postfix Factory
to the classes creating Link
s. However, according to Wikipedia, the factory method pattern is used in the following case:
In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created.
In my case there is only one exact class of objects that will be created by each of the factory classes. There is never another one.
I therefore wonder: do my Factory
classes correspond to the factory pattern ? Or would this naming be confusing as they do not adhere to the factory pattern according to the textbooks?
Link
rather than just letting you donew Link()
. But whether you stick the wordFactory
is up to you. That's purely a style thing and so there's no right answer to it. What people will instead focus on when answering this question is whether in their view you even have a factory.Link
. It so happens thatLink
is the most-derived-type of the objects that are returned by the current implementations.