Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions AbstractFactory-And-Singleton/src/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import button.Button;
import checkbox.Checkbox;
import factory.GUIFactory;

public class App {

private Button button;
private Checkbox checkbox;

public App(GUIFactory factory) {
this.button = factory.createButton();
this.checkbox = factory.createCheckbox();
}

public void paint() {
button.paint();
checkbox.paint();
}
}
44 changes: 44 additions & 0 deletions AbstractFactory-And-Singleton/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import factory.GUIFactory;
import factory.MacOSFactory;
import factory.WindowsFactory;
import java.util.Scanner;

public class Main {

private static GUIFactory macOSFactory = new MacOSFactory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않을 경우에도 메모리를 점유하는 문제가 있는 것 같아요!
사용하고자 할 때에만 생성하는 방식은 어떤가요~?🤔

private static GUIFactory windowsFactory = new WindowsFactory();

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String osKorean = scanner.nextLine();
GUIFactory guiFactory = getOS(osKorean);
if (!validOS(guiFactory)) {
return;
}

App app = new App(guiFactory);
app.paint();

scanner.close();
}

private static boolean validOS(GUIFactory guiFactory) {
if (guiFactory == null) {
System.out.println("그런 OS는 존재하지 않습니다.");
return false;
}
return true;
}

private static GUIFactory getOS(String osKorean) {
switch (osKorean) {
case "맥":
return macOSFactory;
case "윈도우":
return windowsFactory;
default:
return null;
}
}
}
5 changes: 5 additions & 0 deletions AbstractFactory-And-Singleton/src/button/Button.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package button;

public interface Button {
void paint();
}
9 changes: 9 additions & 0 deletions AbstractFactory-And-Singleton/src/button/MacOSButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package button;

public class MacOSButton implements Button {

@Override
public void paint() {
System.out.println("[맥 마우스] 생성됨");
}
}
9 changes: 9 additions & 0 deletions AbstractFactory-And-Singleton/src/button/WindowButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package button;

public class WindowButton implements Button {

@Override
public void paint() {
System.out.println("[윈도우 버튼] 생성됨");
}
}
6 changes: 6 additions & 0 deletions AbstractFactory-And-Singleton/src/checkbox/Checkbox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package checkbox;

public interface Checkbox {

void paint();
}
9 changes: 9 additions & 0 deletions AbstractFactory-And-Singleton/src/checkbox/MacOSCheckbox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package checkbox;

public class MacOSCheckbox implements Checkbox {

@Override
public void paint() {
System.out.println("[맥 체크박스] 생성됨");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package checkbox;

public class WindowCheckbox implements Checkbox {

@Override
public void paint() {
System.out.println("[윈도우 체크박스] 생성됨");
}
}
11 changes: 11 additions & 0 deletions AbstractFactory-And-Singleton/src/factory/GUIFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package factory;

import checkbox.Checkbox;
import button.Button;

public interface GUIFactory {

Button createButton();

Checkbox createCheckbox();
}
19 changes: 19 additions & 0 deletions AbstractFactory-And-Singleton/src/factory/MacOSFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package factory;

import button.MacOSButton;
import checkbox.Checkbox;
import button.Button;
import checkbox.MacOSCheckbox;

public class MacOSFactory implements GUIFactory {

@Override
public Button createButton() {
return new MacOSButton();
}

@Override
public Checkbox createCheckbox() {
return new MacOSCheckbox();
}
}
19 changes: 19 additions & 0 deletions AbstractFactory-And-Singleton/src/factory/WindowsFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package factory;

import button.WindowButton;
import checkbox.Checkbox;
import button.Button;
import checkbox.WindowCheckbox;

public class WindowsFactory implements GUIFactory {

@Override
public Button createButton() {
return new WindowButton();
}

@Override
public Checkbox createCheckbox() {
return new WindowCheckbox();
}
}