객체지향 이론
객체지향 패러다임
새로운 객체를 만들 때 주의 할 점
public class Cell { private int nearbyLandMineCount; private Cell(int nearbyLandMineCount) { this.nearbyLandMineCount = nearbyLandMineCount; } public void updateNearbyLandMineCount(int count) { this.nearbyLandMineCount = count; } }Person person = new Person(); // Getter를 이용하는 경우 if (person.get지갑().get신분증().findAge() >= 19) { pass(); } // 객체의 공개 메서드를 이용 하는 경우 if (person.isAgeGreaterThanOrEqualTo(19)) { pass(); }public class Cell { private static final String FLAG_SIGN = "⚑"; private static final String LAND_MINE_SIGN = "☼"; private static final String UNCHECKED_SIGN = "□"; private static final String EMPTY_SIGN = "■"; private int nearbyLandMineCount; private boolean isLandMine; private boolean isFlagged; private boolean isOpened; public String getSign() { if (isOpened) { if (isLandMine) { return LAND_MINE_SIGN; } if (hasLandMineCount()) { return String.valueOf(nearbyLandMineCount); } return EMPTY_SIGN; } if (isFlagged) { return FLAG_SIGN; } return UNCHECKED_SIGN; } }
SOLID 원칙 알아보기
SRP: Single Responsibility Principle
OCP: Open-Closed Principle
LSP: Liskov Substitution Principle
ISP: Interface Segregation Principle

DIP: Dependency Inversion Principle

Last updated