The factory method pattern is an object-oriented design pattern to implement the concept of factories.
Like other creational patterns, it deals with the problem of creating objects (products) without specifying the exact class of object that will be created. The factory method design pattern handles this problem by defining a separate method for creating the objects, which subclasses can then override to specify the derived type of product that will be created.
Outside the scope of design patterns, the term factory method can also refer to a method of a factory whose main purpose is creation of objects.
Contoh Kasus :
- Mengecat Pintu Mobil dengan pola yang berbeda, pintu ada 4, jenis mobil terserah.
1. create class door.java
public interface door {
public Car draw();
}
2. create class Car.java
public interface Car {
public void drawModel();
public void drawPola();
}
0 komentar:
Posting Komentar