Demo entry 6762050

tt

   

Submitted by anonymous on Oct 10, 2018 at 05:20
Language: Java. Code size: 903 Bytes.

/*** 
 * 
 * @author 16050506126 裴雨斯
 *
 */

interface Reader {
	public void readImage();
}

interface ReaderFactory {
	public Reader createReader();
}

class GifReader implements Reader {
	public void readImage() {
		System.out.println("GifReader start...");
	}
}

class JpgReader implements Reader {
	public void readImage() {
		System.out.println("JpgReader start...");
	}
}

class GifReaderFactory implements ReaderFactory {
	public Reader createReader() {
		return new GifReader();
	}
}

class JpgReaderFactory implements ReaderFactory {
	public Reader createReader() {
		return new JpgReader();
	}
}

public class FactoryTest {

	
	public static void main(String[] args) {
		Reader reader;
		ReaderFactory readerFactory;
		readerFactory = (ReaderFactory)XMUtil.getBean();
		
		reader = readerFactory.createReader();
		reader.readImage();
	}

}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).