์ด๋ฆ„์€ ์–ด๋””์„œ๋“  ์“ฐ์ธ๋‹ค. ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ž˜์ง€์œผ๋ฉด ํŽธํ•˜๋‹ค. ๋ช‡ ๊ฐ€์ง€์˜ ๊ทœ์น™์„ ์•Œ์•„๋ณด์ž.

์˜๋„๋ฅผ ๋ถ„๋ช…ํžˆ ๋ฐํ˜€๋ผ

๋งํ•˜๊ธฐ๋Š” ์‰ฝ์ง€.. ์–ด๋ ต๊ฑฐ๋“ ?

์ €์ž๋„ ์•ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด ์˜๋„๊ฐ€ ๋ถ„๋ช…ํ•œ ์ด๋ฆ„์„ ์ง“๋Š” ๊ฒƒ์€ ์ •๋ง๋กœ ์ค‘์š”ํ•˜๋‹ค. ๊ฒฐ๊ตญ ์ตœ์ข…์ ์œผ๋กœ ์ ˆ์•ฝํ•˜๋Š” ์‹œ๊ฐ„์ด ๋” ๋งŽ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋‚˜ ํฌํ•จํ•ด ๋ฏธ๋ž˜์— ํ–‰๋ณตํ•ด์ง„๋‹ค. ์ฃผ์„์ด ํ•„์š”ํ•˜๋ฉด ์˜๋„๋ฅผ ๋ถ„๋ช…ํžˆ ๋“œ๋Ÿฌ๋‚ด์ง€ ๋ชปํ–ˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

//Bad
int d; // elapsed time in days
//Good
int elapsedTimeInDays;
int daysSinceCreation;
int daysSinceModification;
int fileAgeInDays;
// Bad
public List<int[]> getThem() {
    List<int[]> list1 = new ArrayList<int[]>();
    for (int[] x : theList) {
        if (x[0] == 4) {
            list1.add(x);
        }
    }
    return list1;
}
 
// Good
public List<int[]> getFlaggedCells() {
    List<int[]> flaggedCells = new ArrayList<int[]>();
    for (int[] cell : gameBoard) {
        if (cell[STATUS_VALUE] == FLAGGED) {
            flaggedCells.add(cell);
        }
    }
    return flaggedCells;
}

๋‘ ์˜ˆ์‹œ์—์„œ ํ•ต์‹ฌ์€, ๋‚˜์œ ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ ๋…์ž์—๊ฒŒ โ€œ๊ฐ€์ •โ€์„ ๋ฐ”๋ผ๊ณ  ์žˆ๋‹ค๋Š” ์ ์— ์žˆ๋‹ค. ์ข‹์€ ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ ์ด๋ฆ„ํ•˜๋‚˜๋ฅผ ๋ณ€๊ฒฝํ•˜๊ฒŒ ๋จ์œผ๋กœ์จ ์–ด๋–ค ์˜๋„์ธ์ง€ ๋ช…ํ™•ํ•˜๊ฒŒ ๋“œ๋Ÿฌ๋‚œ๋‹ค.

๊ทธ๋ฆ‡๋œ ์ •๋ณด๋ฅผ ํ”ผํ•˜๋ผ

  • accountList: List? ์ž๋ฃŒ๊ตฌ์กฐ๊ฐ€ List์ธ๊ฑด๊ฐ€?
    • ์ปจํ…Œ์ด๋„ˆ ์œ ํ˜•์„ ์ด๋ฆ„์— ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ง€์–‘ํ•˜์ž.
    • accountGroup, bunchOfAccounts, accounts๋กœ ๋ณ€๊ฒฝ
  • XYZControllerOfStrings, XYZControllerOfContainerStrings: ๋ญ˜ ์จ์•ผํ• ์ง€ ํ—ท๊ฐˆ๋ฆฌ๋„ค..
    • ์„œ๋กœ ํก์‚ฌํ•œ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ์œ ์˜ํ•˜์ž.
    • ์ผ๊ด€์„ฑ์ด ๋–จ์–ด์ง€๋Š” ๊ฒƒ์€ ๊ทธ๋ฆ‡๋œ ์ •๋ณด๋‹ค.

์˜๋ฏธ์žˆ๊ฒŒ ๊ตฌ๋ถ„ํ•˜๋ผ

  • ์Œ ๊ฐœ์ˆ˜๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ๋„ค [a1, a2, โ€ฆ] ์จ์•ผ์ง€
    • ๋ง๋„ ์•ˆ๋˜๊ณ  ์˜๋„๊ฐ€ ํŒŒ์•…๋˜์ง€ ์•Š๋Š” ๋ณ€์ˆ˜๋Š” ์“ฐ์ง€๋งˆ.
  • book ์ด๋ผ๋Š” ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š”๋ฐ ์ด ์ด๋ฆ„์„ ์“ฐ๊ณ  ์‹ถ์–ด. theBook ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋˜๊ฒ ์ง€?
    • ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•œ ๋ชฉ์ ์œผ๋กœ ๋ถˆ์šฉ์–ด๋ฅผ ์ถ”๊ฐ€ํ•˜์ง€๋Š” ๋ง์ž. ๋ฌด์˜๋ฏธํ•˜๋‹ค.
    • ๋ถˆ์šฉ์–ด๊ฐ€ ์˜๋ฏธ์žˆ์„ ๋–„ (ie. ์ง€์—ญ๋ณ€์ˆ˜)์—์„œ๋Š” ์‚ฌ์šฉํ•ด๋„ ๋ฌด๋ฐฉํ•˜๋‹ค. ์œ ์˜๋ฏธํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋ผ๋Š” ๋ง์ด๋‹ค.
    • a์ฒ˜๋Ÿผ ๋ถ™์ด๊ฒŒ ๋˜๋ฉด ๊ฒ€์ƒ‰ํ•  ๋•Œ๋„ ํž˜๋“ค๋‹ค.
  • Name VS NameString
    • ์™œ ๊ตณ์ด String์„ ์ ์–ด์ฃผ๋Š”๊ฐ€? Double ํƒ€์ž…์ด ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์–ด์„œ ๊ทธ๋Ÿฐ๊ฑฐ์•ผ?
  • getActiveAccount() VS getActiveAccounts() VS getActiveAccountInfo()
    • ๋ญ˜ ์จ์•ผํ• ์ง€ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋žŒ์ด ์–ด๋–ป๊ฒŒ ์•Œ์•„?
  • money VS moneyAmount, message VS theMessage
    • ๋งˆ์ฐฌ๊ฐ€์ง€๋‹ค. ๋ญ˜ ์จ์•ผํ• ์ง€ ์–ด๋–ป๊ฒŒ ์•Œ์•„?

๋ฐœ์Œํ•˜๊ธฐ ์‰ฌ์šด ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ผ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ ์‚ฌํšŒ์  ํ™œ๋™์ด๋‹ค. ๋ฐœ์Œํ•˜๊ธฐ ์‰ฌ์šด ๋‹จ์–ด๋Š” ์†Œํ†ต์— ์œ ์šฉํ•˜๋‹ค.

// Bad
class DtaRcrd102 {
    private Date genymdhms;
    private Date modymdhms;
    private final String pszqint = "102";
    /* ... */
};
 
// Good
class Customer {
    private Date generationTimestamp;
    private Date modificationTimestamp;
    private final String recordId = "102";
    /* ... */
};

์•„๋ฌด๋ž˜๋„ ๋งŽ์€ ์˜๋ฏธ๋ฅผ ๋‹ด์€ ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ• ์ˆ˜๋ก ์ข‹๋‹ค. ์œ„์˜ ๊ฒฝ์šฐ ๋ญ๋ผ๊ณ  ํ•˜๋Š”์ง€ ์•Œ ์ˆ˜๊ฐ€ ์—†๋‹ค. ์ง€์ ์ธ ๋Œ€ํ™”๊ฐ€ ๊ฐ€๋Šฅํ•œ๊ฐ€?

๊ฒ€์ƒ‰ํ•˜๊ธฐ ์‰ฌ์šด ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ผ

๋‹จ์ผ ๋ฌธ์ž, ์ˆซ์ž๋ฅผ ๋ณ€์ˆ˜๋ช…์œผ๋กœ ํ•˜์ง€ ๋งˆ๋ผ.

์ผ๋‹จ ์ฐพ๊ธฐ ํž˜๋“ค๋‹ค. ์ค‘๋ณต ์ฒ˜๋ฆฌ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์•„์„œ ๊ฒ€์ƒ‰์ด ์•ˆ๋œ๋‹ค. (์ˆซ์ž: ์ƒ์ˆ˜? ๋ณ€์ˆ˜?) ์˜คํžˆ๋ ค ๊ธด ์ด๋ฆ„์ด ํ›จ์”ฌ ์ข‹๋‹ค.

์ธ์ฝ”๋”ฉ์„ ํ”ผํ•˜์ž

๋ณ€์ˆ˜์— ๋ถ€๊ฐ€ ์ •๋ณด๋ฅผ ๋”ํ•˜์ง€ ๋งˆ๋ผ.

  • ํ—๊ฐ€๋ฆฌ์•ˆ ํ‘œ๊ธฐ๋ฒ•
    • ๋ณ€์ˆ˜๋ช…์— ํ•ด๋‹น ๋ณ€์ˆ˜์˜ Type์„ ์ ์ง€๋งˆ๋ผ
    • ์š”์ฆ˜์€ compiler๊ฐ€ ๋ณ€์ˆ˜ ํƒ€์ž…๊นŒ์ง€ ๋‹ค ์ ๊ฒ€ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด์ œ ํ•„์š”์—†๋‹ค.
  • ๋ฉค๋ฒ„ ๋ณ€์ˆ˜ ์ ‘๋‘์–ด
    • m_property, m_method์™€ ๊ฐ™์€ ์‹์œผ๋กœ ํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.
    • IDE๊ฐ€ ์ƒ‰๊น”์„ ๋‹ค๋ฅด๊ฒŒ ํ•ด์ค€๋‹ค.
    • ์ฝ”๋“œ ์ฝ๋Š” ์‚ฌ๋žŒ๋„ ์ฝ๋‹ค๋ณด๋ฉด m_์€ ์ง€์›Œ๋ฒ„๋ฆฌ๊ณ  ์ฝ์–ด๋ฒ„๋ฆฐ๋‹ค.
    • ์‘.. ๊ตฌ๋‹ฅ๋‹ค๋ฆฌ๋‹ค ๋ผ๋Š” ๋Š๋‚Œ์ด ๊ฐ•ํ•˜๊ฒŒ ๋‚œ๋‹ค.
  • ์ธํ„ฐํŽ˜์ด์Šค์™€ ๊ตฌํ˜„
    • ์ธํ„ฐํŽ˜์ด์Šค ํด๋ž˜์Šค์™€ ๊ตฌํ˜„ ํด๋ž˜์Šค๋ฅผ ๋‚˜๋ˆ ์•ผ ํ•œ๋‹ค๋ฉด ๊ตฌํ˜„ ํด๋ž˜์Šค์˜ ์ด๋ฆ„์— ์ •๋ณด๋ฅผ ์ธ์ฝ”๋”ฉํ•˜์ž.
Do / Donโ€™tInterface classConcrete(Implementation) class
Donโ€™tIShapeFactoryShapeFactory
DoShapeFactoryShapeFactoryImp
DoShapeFactoryCShapeFactory

์ž์‹ ์˜ ๊ธฐ์–ต๋ ฅ์„ ์ž๋ž‘ํ•˜์ง€ ๋งˆ๋ผ

์Œ ๋‚ด ์ง€์  ๋Šฅ๋ ฅ์„ ๊ณผ์‹œํ•ด์•ผ ๊ฒ ์–ด. ์•„๋ฌด๋„ ๋ชจ๋ฅด๊ฒŒ ๋ณ€ํƒœ๊ฐ™์€ ๋ณ€์ˆ˜๋ฅผ ์จ์•ผ์ง€. c

๋…์ž๊ฐ€ ๋จธ๋ฆฌ์†์œผ๋กœ ํ•œ๋ฒˆ ๋” ์ƒ๊ฐํ•ด ๋ณ€ํ™˜ํ•ด์•ผ ํ• ๋งŒํ•œ ๋ณ€์ˆ˜๋ช…์„ ์“ฐ์ง€ ๋ง์ž. ์ „๋ฌธ๊ฐ€๋Š” ๋ช…๋ฃŒํ•จ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋‚จ๋“ค์ด ์ดํ•ดํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๋‚ด๋†“๋Š”๋‹ค.

ํด๋ž˜์Šค ์ด๋ฆ„

๋ช…์‚ฌ ํ˜น์€ ๋ช…์‚ฌ๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ผ. ๋™์‚ฌ๋Š” ์•ˆ๋œ๋‹ค.

GoodBad
Customer, WikiPage, Account, AddressParserManager, Processor, Data, Info

๋ฉ”์„œ๋“œ ์ด๋ฆ„

  • ๋™์‚ฌ ํ˜น์€ ๋™์‚ฌ๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ผ.
    • postPayment, deletePayment, deletePage, save
  • ์ ‘๊ทผ์ž, ๋ณ€๊ฒฝ์ž, ์กฐ๊ฑด์ž๋Š” get, set, is๋กœ ์‹œ์ž‘ํ•˜์ž.
    • ์ ‘๊ทผ์ž: get
    • ๋ณ€๊ฒฝ์ž: set
    • ์กฐ๊ฑด์ž: is, has, should
  • ์ƒ์„ฑ์ž๋ฅผ ์˜ค๋ฒ„๋กœ๋“œํ•  ๊ฒฝ์šฐ ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ํ•ด๋‹น ์ƒ์„ฑ์ž๋ฅผ private์œผ๋กœ ์„ ์–ธํ•˜์ž.
// ์ฒซ๋ฒˆ์งธ ๋ณด๋‹ค ๋‘ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์ด ๋” ์ข‹๋‹ค.  
Complex fulcrumPoint = new Complex(23.0);  
Complex fulcrumPoint = Complex.FromRealNumber(23.0);  

๊ธฐ๋ฐœํ•œ ์ด๋ฆ„์€ ํ”ผํ•˜๋ผ

ํŠน์ • ๋ฌธํ™”์—์„œ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ์žฌ๋ฏธ์žˆ๋Š” ์ด๋ฆ„๋ณด๋‹ค ์˜๋„๋ฅผ ๋ถ„๋ช…ํžˆ ํ‘œํ˜„ํ•˜๋Š” ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜์ž. ์ž์นซํ•˜๋ฉด ์œ ๋จธ๊ฐ๊ฐ์ด ๋›ฐ์–ด๋‚œ ์‚ฌ๋žŒ๋งŒ ๋ณ€์ˆ˜ ์˜๋„๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.

HolyHandGrenade โ†’ DeleteItems
whack() โ†’ kill()

ํ•œ ๊ฐœ๋…์— ํ•œ ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ผ

์ถ”์ƒ์ ์ธ ๊ฐœ๋… ํ•˜๋‚˜์— ๋‹จ์–ด ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•˜์ž.

  • fetch, retrieve, get
  • controller, manager, driver

๋„๋Œ€์ฒด ๋ฌด์Šจ ์ฐจ์ด์ง€? ๊ตฌ๋ถ„ํ•ด์„œ ์ž‘์„ฑํ•œ๋‹ค๋ฉด, ์ฝ์„ ๋•Œ, ์ฐจ์ด์ ์„ ํ•œ๋ฒˆ์— ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๋ง ์žฅ๋‚œ์„ ํ•˜์ง€๋งˆ๋ผ

ํ•œ ๋‹จ์–ด๋ฅผ ๋‘ ๊ฐ€์ง€ ๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜์ง€ ๋ง์ž.

public static String add(String message, String messageToAppend)  // A + B์˜ ์˜๋ฏธ
public List<Element> add(Element element)  // ๊ธฐ์กด ๊ฒƒ์— "์ถ”๊ฐ€"ํ•œ๋‹ค๋Š” ์˜๋ฏธ

์˜๋ฏธ๋ก ์ ์œผ๋กœ ํ–‰๋™์ด ๋‹ค๋ฅธ ์ƒํ™ฉ์ด๋‚˜, ์ผ๋ฐ˜์ ์œผ๋กœ ๋ถ€๋ฅด๋Š” ์ด๋ฆ„์ด ๊ฐ™์•„ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์ด๋‹ค. ํ–‰์œ„๊ฐ€ ๋‹ค๋ฅด๋‹ค๋ฉด ๋‹ค๋ฅธ ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. ์œ„ ๊ฒฝ์šฐ insert, append์™€ ๊ฐ™์€ ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ๋‹ค.

ํ•ด๋ฒ• ์˜์—ญ์—์„œ ๊ฐ€์ ธ์˜จ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ผ

์ „์‚ฐ์šฉ์–ด, ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ด๋ฆ„, ํŒจํ„ด ์ด๋ฆ„, ์ˆ˜ํ•™ ์šฉ์–ด ๋“ฑ์€ ์‚ฌ์šฉํ•˜์ž.

๊ฐœ๋ฐœ์ž๋ผ๋ฉด ๋‹น์—ฐํžˆ ์•Œ๊ณ  ์žˆ์„ JobQueue, AccountVisitor(Visitor pattern)๋“ฑ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ์ด์œ ๋Š” ์—†๋‹ค.

๋ฌธ์ œ ์˜์—ญ์—์„œ ๊ฐ€์ ธ์˜จ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ผ

์ ์ ˆํ•œ ํ”„๋กœ๊ทธ๋ž˜๋จธ ์šฉ์–ด๊ฐ€ ์—†๊ฑฐ๋‚˜ ๋ฌธ์ œ์˜์—ญ๊ณผ ๊ด€๋ จ์ด ๊นŠ์€ ์šฉ์–ด์˜ ๊ฒฝ์šฐ ๋ฌธ์ œ ์˜์—ญ ์šฉ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ž.

์šฐ์ˆ˜ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋จธ/์„ค๊ณ„์ž๋ผ๋ฉด ํ•ด๋ฒ• ์˜์—ญ๊ณผ ๋ฌธ์ œ ์˜์—ญ์„ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. ๊ทธ ์ค‘ ์–ด๋–ค ๊ฒƒ์ด ๋” ์˜ณ์€ ํŒ๋‹จ์ธ์ง€ ๊ฒฐ๋ก ์„ ๋‚ด๋ฆด ์ˆ˜ ์žˆ๋Š” ํŒ๋‹จ๋ ฅ์„ ๊ฐ€์ ธ์•ผ ํ•œ๋‹ค.

์˜๋ฏธ์žˆ๋Š” ๋งฅ๋ฝ์„ ์ถ”๊ฐ€ํ•˜๋ผ

ํด๋ž˜์Šค, ํ•จ์ˆ˜, namespace๋“ฑ์œผ๋กœ ๊ฐ์‹ธ์„œ ๋งฅ๋ฝ(Context)์„ ํ‘œํ˜„ํ•˜๋ผ

๊ทธ๋ž˜๋„ ๋ถˆ๋ถ„๋ช…ํ•˜๋‹ค๋ฉด ์ ‘๋‘์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ž.

// Bad
private void printGuessStatistics(char candidate, int count) {
    String number;
    String verb;
    String pluralModifier;
    if (count == 0) {  
        number = "no";  
        verb = "are";  
        pluralModifier = "s";  
    }  else if (count == 1) {
        number = "1";  
        verb = "is";  
        pluralModifier = "";  
    }  else {
        number = Integer.toString(count);  
        verb = "are";  
        pluralModifier = "s";  
    }
    String guessMessage = String.format("There %s %s %s%s", verb, number, candidate, pluralModifier );
 
    print(guessMessage);
}

์ด ์ƒํ™ฉ์—์„œ ๋งˆ์Œ์— ๋“ค์ง€ ์•Š๋Š” ๊ฒƒ๋“ค์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  1. ํ•จ์ˆ˜๊ฐ€ ๊ธธ๋‹ค.
  2. ์„ธ ๋ณ€์ˆ˜๋ฅผ ํ•˜๋‚˜์˜ ํ•จ์ˆ˜ ์ „๋ฐ˜์—์„œ ์‚ฌ์šฉํ•œ๋‹ค.

์ด๋ฅผ ํด๋ž˜์Šค๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ์ฒ˜๋ฆฌํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์•„์ง„๋‹ค.

// Good
public class GuessStatisticsMessage {
    private String number;
    private String verb;
    private String pluralModifier;
 
    public String make(char candidate, int count) {
        createPluralDependentMessageParts(count);
        return String.format("There %s %s %s%s", verb, number, candidate, pluralModifier );
    }
 
    private void createPluralDependentMessageParts(int count) {
        if (count == 0) {
            thereAreNoLetters();
        } else if (count == 1) {
            thereIsOneLetter();
        } else {
            thereAreManyLetters(count);
        }
    }
 
    private void thereAreManyLetters(int count) {
        number = Integer.toString(count);
        verb = "are";
        pluralModifier = "s";
    }
 
    private void thereIsOneLetter() {
        number = "1";
        verb = "is";
        pluralModifier = "";
    }
 
    private void thereAreNoLetters() {
        number = "no";
        verb = "are";
        pluralModifier = "s";
    }
}

๋ถˆํ•„์š”ํ•œ ๋งฅ๋ฝ์„ ์—†์• ๋ผ

์Œ, ์ด A ํ”„๋กœ์ ํŠธ๋‹ˆ๊นŒ Class ์•ž์— A๋ฅผ ๋‹ฌ์•„์„œ ๊ด€๋ฆฌํ•˜๋ฉด ์ข‹๊ฒ ์ง€?

์‘ ํฐ์ผ๋‚œ๋‹ค. IDE์—์„œ A๋ฅผ ์ž…๋ ฅํ•˜์ž๋งˆ์ž ๊ด€๋ จ๋œ ๋ชจ๋“  ํด๋ž˜์Šค๋ฅผ ์—ด๊ฑฐํ•˜๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค. ๊ทธ ๋ฟ์ด ์•„๋‹ˆ๋‹ค. a์ฒ˜๋Ÿผ ์ ‘๋‘์–ด๋ฅผ ๋ถ™์ด๋Š” ๊ฒƒ์€ ๋ชจ๋“ˆ์˜ ์žฌ์‚ฌ์šฉ ๊ด€์ ์—์„œ๋„ ์ข‹์ง€ ๋ชปํ•˜๋‹ค. ์žฌ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ด๋ฆ„์„ ๋ฐ”๊ฟ”์•ผ ํ•œ๋‹ค. GSDAccountAddress ๋Œ€์‹  Address๋กœ๋งŒ ํ•ด๋„ ์ถฉ๋ถ„ํ•˜๋‹ค. ์–ด๋–ป๊ฒŒ ๋ณด๋ฉด ํ•„์š”์—†๋Š” ์ถ”๊ฐ€ ๋‹จ์–ด๊ฐ€ ๋“ค์–ด๊ฐ€๊ฒŒ ๋œ ๊ฒƒ์ด๋‹ค.

Summary

์ซ„์ง€๋ง๊ณ  ๋งํ•˜์ž.

์ข‹์€ ์ด๋ฆ„์€ ์—ฌ๋Ÿฌ ๋Šฅ๋ ฅ์„ ์š”๊ตฌํ•˜๋Š” ์ผ์ด๋‹ค.

  • ์„ค๋ช… ๋Šฅ๋ ฅ
  • ๋ฌธํ™”์  ๋ฐฐ๊ฒฝ

์ฆ‰, ๊ต์œก์ ์ธ ์ธก๋ฉด์ด ๊ฐ€์žฅ ๊ฐ•ํ•˜๋‹ค. ์ด๋ฆ„์„ ๋ฐ”๊พธ์ง€ ์•Š์œผ๋ ค๋Š” ์ด์œ ๋Š” ์‚ฌํšŒ์  ์ด์œ ๊ฐ€ ๊ฐ€์žฅ ํฌ๋‹ค. ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ฐ˜๋Œ€ํ• ๊นŒ๋ด. ํ•˜์ง€๋งŒ ์˜คํžˆ๋ ค ๋ฐ˜๊ฐ‘๊ณ  ๊ณ ๋งˆ์›Œํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ์— ๊ฐ€๊น๋‹ค. ๋‘๋ ค์›Œํ•˜์ง€ ๋ง๊ณ  ์„œ๋กœ์˜ ๋ช…๋ช…์„ ์ง€์ ํ•˜๊ณ  ๊ณ ์น˜์ž. ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด ์ด๋ฆ„์„ ์™ธ์šฐ๋Š” ๊ฒƒ์— ์‹œ๊ฐ„์„ ๋นผ์•—๊ธฐ์ง€ ์•Š๊ณ  โ€œ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ฝํžˆ๋Š” ์ฝ”๋“œโ€๋ฅผ ์งœ๋Š” ๋ฐ์— ๋” ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

Reference