Is this Factory Method creation pattern?

前端 未结 20 845
再見小時候
再見小時候 2020-12-12 17:12

I have been using factory method creation pattern for awhile now. I was just recently told that this:

public static class ScheduleTypeFactory
{
    public st         


        
20条回答
  •  暖寄归人
    2020-12-12 17:44

    Sure looks like the factory pattern to me. I don't see anything wrong with your implementation.

    From Factory method pattern:

    The essence of the Factory Pattern is to "Define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses."

    This is exactly what you are doing.

    As a side note: a good rule of thumb is that whenever someone tells you something and is unable or unwilling to provide a rationale for their statement, there is a good chance they are unqualified to make the statement at all.

提交回复
热议问题