Is this Factory Method creation pattern?

前端 未结 20 877
再見小時候
再見小時候 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:58

    Well, Wikipedia says it is a factory method:

    public class ImageReaderFactory 
    {
        public static ImageReader getImageReader( InputStream is ) 
        {
            int imageType = figureOutImageType( is );
    
            switch( imageType ) 
            {
                case ImageReaderFactory.GIF:
                    return new GifReader( is );
                case ImageReaderFactory.JPEG:
                    return new JpegReader( is );
                // etc.
            }
        }
    }
    

提交回复
热议问题