Skip to content

Latest commit

ย 

History

History

04. Inheritance

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Inheritance

  1. Introduction
  2. Base Classes and Derived Classes
  3. Protected Members
  4. CommissionEmployee Class
  5. BasePlusCommissionEmployeeClass WITHOUT Using Inheritance
  6. Creating an Inheritance Hierarchy
  7. Inheritance Hierarchy Using protected Data
  8. Inheritance Hierarchy Using private Data
  9. ์ƒ์† ๊ตฌ์กฐ์—์„œ ์ƒ์„ฑ์ž, ์†Œ๋ฉธ์ž์˜ ์‹คํ–‰ ์ˆœ์„œ
  10. public, protected and private Inheritance

1. Introduction

๊ฐ์ฒด์ง€ํ–ฅ ์„ค๊ณ„ (object-oriented design)

  • ์ด๋ฏธ ๋งŒ๋“ค์–ด์ง„ ํด๋ž˜์Šค๋ฅผ ํŒŒ์ƒ์‹œ์ผœ ์ƒˆ๋กœ์šด ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“œ๋Š” ์ƒ์†(inheritance) แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 5 08 19

Inheritance (์ƒ์†)

  • ์†Œํ”„ํŠธ์›จ์–ด ์žฌ์‚ฌ์šฉ์„ ์œ„ํ•œ ํšจ๊ณผ์ ์ธ ๋ฐฉ๋ฒ•
  • ๊ธฐ์กด ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์ƒˆ๋กœ์šด ํด๋ž˜์Šค ์ƒ์„ฑ
    • ๊ธฐ์กด ํด๋ž˜์Šค์˜ ์†์„ฑ๊ณผ ํ–‰๋™ ๋ฐฉ์‹์„ ํก์ˆ˜
    • ์ƒˆ๋กœ์šด ์†์„ฑ๊ณผ ํ–‰๋™ ๋ฐฉ์‹์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ณด๋‹ค ๊ตฌ์ฒดํ™”ํ•จ
  • ๊ธฐ๋ณธ ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์ƒ์†๋ฐ›์•„ ํŒŒ์ƒ ํด๋ž˜์Šค๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.
    • ๊ฐ์ฒด๋“ค์˜ ๋” ํŠนํ™”๋œ(specialized) ๊ทธ๋ฃน
    • ๊ธฐ๋ณธ ํด๋ž˜์Šค (base class)๋กœ๋ถ€ํ„ฐ ํ–‰๋™ ๋ฐฉ์‹์„ ์ƒ์† ๋ฐ›์Œ
      • ์ž์‹ ๋งŒ์˜ ํ–‰๋™ ๋ฐฉ์‹์œผ๋กœ ํŠนํ™”(customize) ๊ฐ€๋Šฅ
    • ์ถ”๊ฐ€์ ์ธ ํ–‰๋™ ๋ฐฉ์‹๋„ ํฌํ•จ

2. Base Classes and Derived Classes

ํด๋ž˜์Šค ๊ณ„์ธต (class hierarchy)

  • ์ง์ ‘ ๊ธฐ๋ณธ ํด๋ž˜์Šค (direct base class)
    • ์ง์ ‘ ์ƒ์† ๋ฐ›์€ ๋ฐ”๋กœ ์œ„ ๋‹จ๊ณ„ ๊ธฐ๋ณธ ํด๋ž˜์Šค
  • ๊ฐ„์ ‘ ๊ธฐ๋ณธ ํด๋ž˜์Šค (indirect base class)
    • ๋‘ ๋‹จ๊ณ„ ์ด์ƒ ์ƒ์œ„์˜ ๊ธฐ๋ณธ ํด๋ž˜์Šค
  • ๋‹จ์ผ ์ƒ์† (single inheritance)
    • ํ•˜๋‚˜์˜ ๊ธฐ๋ณธ ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์ƒ์†
  • ๋‹ค์ค‘ ์ƒ์† (multiple inheritance)
    • ๋‘ ๊ฐœ ์ด์ƒ์˜ ๊ธฐ๋ณธ ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์ƒ์† แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 5 10 18

์ƒ์†์˜ ์„ธ ์ข…๋ฅ˜

  • public

    • ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋Š” ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ๊ฐ์ฒด์ด๊ธฐ๋„ ํ•˜๋‹ค.
      • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋Š” ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๊ฐ€ ๋  ์ˆ˜ ์—†๋‹ค.
      • e.g., ๋ชจ๋“  ์ž๋™์ฐจ๋Š” ํƒˆ ๊ฒƒ์ด๋‹ค, ๊ทธ๋Ÿฌ๋‚˜ ๋ชจ๋“  ํƒˆ ๊ฒƒ์€ ์ฐจ๊ฐ€ ์•„๋‹ˆ๋‹ค.
    • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ non-private ๋ฉค๋ฒ„์— ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๋‹ค.
      • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ private ๋ฉค๋ฒ„์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”
        • ํŒŒ์ƒ ํด๋ž˜์Šค๋Š” ๋ฐ˜๋“œ์‹œ ์ƒ์†๋ฐ›์€ non-private ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.
  • private, protected ์ž˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋ณธ ๊ฐ•์˜์—์„œ๋Š” public ์ƒ์†์— ์ดˆ์ 

์ƒ์† ๊ด€๊ณ„์˜ ์˜๋ฏธ

  • ์ถ”์ƒํ™”(abstraction)
    • ์‹œ์Šคํ…œ์˜ ๋ชจ๋“  ๊ฐ์ฒด๋“ค์˜ ๊ณตํ†ต์„ฑ์— ์ฃผ๋ชฉ
  • โ€œis-aโ€ ๊ด€๊ณ„ vs. โ€œhas-aโ€ ๊ด€๊ณ„
    • โ€œis-aโ€ ๊ด€๊ณ„ โ€“ ์ƒ์†
      • ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋Š” ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ๊ฐ์ฒด์ฒ˜๋Ÿผ ๋‹ค๋ค„์ง„๋‹ค.
      • e.g., ์ฐจ๋Š” ํƒˆ ๊ฒƒ์ด๋‹ค. (Car is a vehicle)
    • โ€œhas-aโ€ ๊ด€๊ณ„ โ€“ ๋ณตํ•ฉ (composition) ๊ด€๊ณ„
      • ๊ฐ์ฒด๊ฐ€ ๋‹ค๋ฅธ ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋ฅผ ๋ฉค๋ฒ„๋กœ ํฌํ•จํ•˜๋Š” ๊ฒƒ
      • e.g., ์ฐจ์—๋Š” ์šด์ „๋Œ€๊ฐ€ ์žˆ๋‹ค. (Car has a steering wheel)

Software Engineering Observation

Member functions of a derived class cannot directly access private members of the base class.

๊ธฐ๋ณธ ํด๋ž˜์Šค๋Š” ํŒŒ์ƒ ํด๋ž˜์Šค๋ณด๋‹ค ๋” ๋„“์€ ๋ฒ”์œ„์˜ ๊ฐ์ฒด๋ฅผ ํ‘œํ˜„

  • e.g.,
    • ๊ธฐ๋ณธ ํด๋ž˜์Šค : Vehicle
      • ์ฐจ(car), ํŠธ๋Ÿญ, ๋ณดํŠธ, ์ž์ „๊ฑฐ ๋“ฑ์„ ํฌํ•จ
    • ํŒŒ์ƒ ํด๋ž˜์Šค : Car
      • ์ž‘๊ณ  ๋ณด๋‹ค ํŠนํ™”๋œ ํƒˆ ๊ฒƒ(vehicle)์˜ ์ข…๋ฅ˜
Base class Derived classes
Student GraduateStudent, UndergraduateStudent
Shape Circle, Triangle, Rectangle, Sphere, Cube
Loan CarLoan, HomeImprovementLoan, MortgageLoad
Employee Faculty, Staff
Account CheckingAccount, SavingAccount

์ƒ์† ๊ณ„์ธต ๊ตฌ์กฐ (Inheritance hierarachy)

  • ์ƒ์† ๊ด€๊ณ„๋Š” ํŠธ๋ฆฌ(tree) ํ˜•ํƒœ์˜ ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ํ˜•์„ฑํ•œ๋‹ค.
  • ๊ฐ ํด๋ž˜์Šค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
    • ๊ธฐ๋ณธ ํด๋ž˜์Šค (base class)
      • : ํŒŒ์ƒ ํด๋ž˜์Šค์— ์†์„ฑ / ํ–‰๋™ ๋ฐฉ์‹์„ ๊ณต๊ธ‰ํ•œ๋‹ค.
    • ํŒŒ์ƒ ํด๋ž˜์Šค (derived class)
      • : ๊ธฐ๋ณธ ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์†์„ฑ / ํ–‰๋™ ๋ฐฉ์‹์„ ์ƒ์†๋ฐ›๋Š”๋‹ค

3. Protected Members

Public ์ƒ์†

  • e.g,
    • Class TwoDimensionalShape : public Shape
    • : TwoDimensionalShape ํด๋ž˜์Šค๋Š” Shape ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์ƒ์† ๋ฐ›์Œ
  • ๊ธฐ๋ณธ ํด๋ž˜์Šค private ๋ฉค๋ฒ„
    • ์ง์ ‘์ ์œผ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์—†์ง€๋งŒ ์ƒ์†๋œ๋‹ค. - ์ƒ์†๋œ public ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค. แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 5 26 58

์ ‘๊ทผ ์ง€์ •์ž protected

  • protected ์ ‘๊ทผ
    • public ๊ณผ private์˜ ์ค‘๊ฐ„ ๋ณดํ˜ธ ๋‹จ๊ณ„
    • protected ๋ฉค๋ฒ„๋Š” ๋‹ค์Œ์„ ํ†ตํ•ด ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๋‹ค.
      • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ๋ฉค๋ฒ„์™€ ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ๋ฉค๋ฒ„
  • ํŒŒ์ƒ ํด๋ž˜์Šค ๋ฉค๋ฒ„
    • ๊ธฐ๋ณธ ๋ฉค๋ฒ„์˜ public ๊ณผ protected ๋ฉค๋ฒ„์— ์ง์ ‘ ์ ‘๊ทผ ๊ฐ€๋Šฅ
      • ๊ฐ„๋‹จํžˆ ๋ฉค๋ฒ„ ์ด๋ฆ„์„ ์‚ฌ์šฉ
    • ํŒŒ์ƒ ํด๋ž˜์Šค์—์„œ ์žฌ์ •์˜๋œ ๊ธฐ๋ณธ ํด๋ž˜์Šค ๋ฉค๋ฒ„๋Š” ๊ธฐ๋ณธ ํด๋ž˜์Šค ์ด๋ฆ„๊ณผ ์ดํ•ญ ์Šค์ฝ”ํ”„ ์‹๋ณ„ ์—ฐ์‚ฐ์ž(::) ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.
      • e.g., shape::area

Protected๋กœ ์„ ์–ธ๋œ ๋ณ€์ˆ˜๊ฐ€ ํ—ˆ์šฉํ•˜๋Š” ์ ‘๊ทผ์˜ ๋ฒ”์œ„

IMG_FF955B32D458-1

4. CommissionEmployee Class

๊ธฐ๋ณธ ํด๋ž˜์Šค์™€ ํŒŒ์ƒ ํด๋ž˜์Šค ์˜ˆ์ œ ๊ฐœ์š”

  • CommissionEmployee โ€“ BasePlusCommissionEmployee ์ƒ์† ๊ณ„์ธต
    • CommissionEmployee
      • First name, last name, SSN, commission rate, gross sale amount
    • BasePlusCommissionEmployee
      • First name, last name, SSN, commission rate, gross sale amount
      • ๊ธฐ๋ณธ ๋ด‰๊ธ‰
    • ใˆœ Commission Employee: ํŒ๋งค ๊ธˆ์•ก์˜ ์ผ๋ถ€๋ฅผ ์ˆ˜๋‹น์œผ๋กœ ๊ฐ€์ ธ๊ฐ€๋Š” ์˜์—… ์‚ฌ์› (๊ธฐ๋ณธ ์›”๊ธ‰์ด ์žˆ์„ ์ˆ˜๋„, ์—†์„ ์ˆ˜๋„ ์žˆ์Œ)

CommissionEmployee ํด๋ž˜์Šค ๊ตฌ์„ฑ

  • CommissionEmployee ํ—ค๋” ํŒŒ์ผ (๋‹ค์Œ ์˜ˆ์ œ)
    • public services
      • ์ƒ์„ฑ์ž
      • get ๊ณผ set ํ•จ์ˆ˜
      • ๋ฉค๋ฒ„ ํ•จ์ˆ˜ earnings, print
  • CommissionEmployee ์†Œ์Šค ์ฝ”๋“œ ํŒŒ์ผ (๋‹ค์Œ ์˜ˆ์ œ)

CommissionEmployee ํด๋ž˜์Šค ์˜ˆ์ œ

CommissionEmployee.h

#ifndef COMMISSION_H
#define COMMISSION_H

#include <string>
using std::string;

class CommissionEmployee
{
public:
    CommissionEmployee(const string &, const string &, const string &, double = 0.0, double = 0.0);

    void setFirstName(const string &);
    string getFirstName() const;

    void setLastName(const string &);
    string getLastName() const;

    void setSocialSecurityNumber(const string &);
    string getSocialSecurityNumber() const;

    void setGrossSales(double);
    double getGrossSales() const;

    void setCommissionRate(double);
    double getCommissionRate() const;

    double earnings() const;
    void print() const;

private:
    string firstName;
    string lastName;
    string socialSecurityNumber;
    double grossSales;
    double commissionRate;
};

#endif

CommissionEmployee.cpp

#include <iostream>
using std::cout;

#include "CommissionEmployee.h"

CommissionEmployee::CommissionEmployee(
    const string &first, const string &last, const string &ssn,
    double sales, double rate)
{
    firstName = first;
    lastName = last;
    socialSecurityNumber = ssn;
    setGrossSales(sales);
    setCommissionRate(rate);
}

void CommissionEmployee::setFirstName(const string &first)
{
    firstName = first;
}

string CommissionEmployee::getFirstName() const
{
    return firstName;
}

void CommissionEmployee::setLastName(const string &last)
{
    lastName = last;
}

string CommissionEmployee::getLastName() const
{
    return lastName;
}

void CommissionEmployee::setSocialSecurityNumber(const string &ssn)
{
    socialSecurityNumber = ssn;
}

string CommissionEmployee::getSocialSecurityNumber() const
{
    return socialSecurityNumber;
}

void CommissionEmployee::setGrossSales(double sales)
{
    grossSales = (sales < 0.0) ? 0.0 : sales;
}

double CommissionEmployee::getGrossSales() const
{
    return grossSales;
}

void CommissionEmployee::setCommissionRate(double rate)
{
    commissionRate = (rate > 0.0 && rate < 1.0) ? rate : 0.0;
}

double CommissionEmployee::getCommissionRate() const
{
    return commissionRate;
}

double CommissionEmployee::earnings() const
{
    return commissionRate * grossSales;
}

void CommissionEmployee::print() const
{
    cout << "commission employee: " << firstName << ' ' << lastName
         << "\nsocial security number: " << socialSecurityNumber
         << "\ngross sales: " << grossSales
         << "\ncommission rate: " << commissionRate;
}

main.cpp

#include <iostream>
using std::cout;
using std::endl;
using std::fixed;

#include <iomanip>
using std::setprecision;

#include "CommissionEmployee.h"

int main()
{
    CommissionEmployee employee(
        "Sue", "Jones", "222-22-2222", 10000, .06);

    cout << fixed << setprecision(2);

    cout << "Employee information obtained by get functions: \n"
         << "\nFirst name is " << employee.getFirstName()
         << "\nLast name is " << employee.getLastName()
         << "\nSocial security number is " << employee.getSocialSecurityNumber()
         << "\nGross sales is " << employee.getGrossSales()
         << "\nCommission rate is " << employee.getCommissionRate() << endl;

    employee.setGrossSales(8000);
    employee.setCommissionRate(.1);

    cout << "\nUpdate employee information output: " << endl;
    employee.print();

    cout << "\n\nEmployee's earnings: $" << employee.earnings() << endl;

    return 0;
}

5. BasePlusCommissionEmployeeClass WITHOUT Using Inheritance

์ƒ์†์„ ์ด์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•œ BasePlusCommissionEmployee ํด๋ž˜์Šค

  • CommissionEmployee ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์ƒ์†๋ฐ›์•„ ํŒŒ์ƒ
    • is-a CommissionEmployee
    • ๋ชจ๋“  public ๋ฉค๋ฒ„ ์ƒ
  • ์ƒ์„ฑ์ž๋Š” ์ƒ์†๋˜์ง€ ์•Š๋Š”๋‹ค.
    • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„ ์ดˆ๊ธฐํ™”๋ฅผ ์œ„ํ•ด ๊ธฐ๋ณธ ํด๋ž˜์Šค ์ดˆ๊ธฐํ™” ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉ
  • ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„ baseSalary๋ฅผ ๊ฐ–๋Š”๋‹ค.

BasePlusCommissionEmployee.h

#ifndef BASEPLUS_H
#define BASEPLUS_H

#include <string>
using std::string;

#include "CommissionEmployee.h"

class BasePlusCommissionEmployee : public CommissionEmployee
{
public:
    BasePlusCommissionEmployee(const string &, const string &, const string &,
                               double = 0.0, double = 0.0, double = 0.0);

    void setBaseSalary(double);
    double getBaseSalary() const;

    double earnings() const;
    void print() const;

private:
    double baseSalary;
};

#endif

BasePlusCommissionEmployee.cpp

#include <iostream>
using std::cout;

#include "BasePlusCommissionEmployee.h"

BasePlusCommissionEmployee::BasePlusCommissionEmployee(
    const string &first, const string &last, const string &ssn,
    double sales, double rate, double salary)
    : CommissionEmployee(first, last, ssn, sales, rate)
{
    setBaseSalary(salary);
}

void BasePlusCommissionEmployee::setBaseSalary(double salary)
{
    baseSalary = (salary < 0.0) ? 0.0 : salary;
}

double BasePlusCommissionEmployee::getBaseSalary() const
{
    return baseSalary;
}

double BasePlusCommissionEmployee::earnings() const
{
    return baseSalary + (commissionRate * grossSales);
}

void BasePlusCommissionEmployee::print() const
{
    cout << "base-salaried commission emplyee: " << firstName << ' '
         << lastName << "\nsocial security number: " << socialSecurityNumber
         << "\ngross sales: " << grossSales
         << "\ncommission rate: " << commissionRate
         << "\nbase salary: " << baseSalary;
}

์ƒ์†์€ ์ž˜ ๋˜์—ˆ์œผ๋‚˜, Base class์˜ Private ๋ฉค๋ฒ„์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ์‹์—์„œ ์ปดํŒŒ์ผ ์˜ค๋ฅ˜ ๋ฐœ์ƒ

6. Creating an Inheritance Hierarchy

  • ๊ธฐ๋ณธ ํด๋ž˜์Šค ํ—ค๋” ํŒŒ์ผ์„ include ํ•œ๋‹ค.
    • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ํ—ค๋” ํŒŒ์ผ์€ ๋‹ค์Œ ์„ธ๊ฐ€์ง€๋กœ ์ด์œ ๋กœ ๋ฐ˜๋“œ์‹œ ํŒŒ์ƒ ํด๋ž˜์Šค ํ—ค๋” ํŒŒ์ผ์— include ๋˜์–ด์•ผ ํ•œ๋‹ค.
      • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ์กด์žฌ๋ฅผ ์•Œ๊ธฐ ์œ„ํ•ด
      • ์ƒ์†๋œ ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„์˜ ํฌ๊ธฐ๋ฅผ ์•Œ๊ธฐ ์œ„ํ•ด
      • ์ƒ์†๋œ ํด๋ž˜์Šค์˜ ๋ฉค๋ฒ„๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”์ง€ ์•Œ๊ธฐ ์œ„ํ•ด

7. Inheritance Hierarchy Using protected Data

Protected ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ

  • BasePlusCommissionEmployee ํด๋ž˜์Šค (ํŒŒ์ƒ ํด๋ž˜์Šค)๊ฐ€ ๊ธฐ๋ณธ ํด๋ž˜์Šค
    • (CommissionEmployee) ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„์— ์ง์ ‘ ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ protected ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.
  • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ protected ๋ฉค๋ฒ„๋Š” ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ๋ชจ๋“  ํŒŒ์ƒ ํด๋ž˜์Šค์— ์ƒ์†๋˜๋ฉฐ ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ๋ฉค๋ฒ„ ํ•จ์ˆ˜์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

Protected ๋ฉค๋ฒ„๋ฅผ ์ด์šฉํ•œ CommissionEmployee ํด๋ž˜์Šค ๊ฐœ์„ 

CommissionEmployee.h

#ifndef COMMISSION_H
#define COMMISSION_H

#include <string>
using std::string;

class CommissionEmployee
{
public:
    CommissionEmployee(const string &, const string &, const string &, double = 0.0, double = 0.0);

    void setFirstName(const string &);
    string getFirstName() const;

    void setLastName(const string &);
    string getLastName() const;

    void setSocialSecurityNumber(const string &);
    string getSocialSecurityNumber() const;

    void setGrossSales(double);
    double getGrossSales() const;

    void setCommissionRate(double);
    double getCommissionRate() const;

    double earnings() const;
    void print() const;

protected:
    string firstName;
    string lastName;
    string socialSecurityNumber;
    double grossSales;
    double commissionRate;
};

#endif

BasePlusCommissionEmployee.h

#ifndef BASEPLUS_H
#define BASEPLUS_H

#include <string>
using std::string;

#include "CommissionEmployee.h"

class BasePlusCommissionEmployee : public CommissionEmployee
{
public:
    BasePlusCommissionEmployee(const string &, const string &, const string &,
                               double = 0.0, double = 0.0, double = 0.0);

    void setBaseSalary(double);
    double getBaseSalary() const;

    double earnings() const;
    void print() const;

private:
    double baseSalary;
};

#endif

BasePlusCommissionEmployee.cpp

#include <iostream>
using std::cout;

#include "BasePlusCommissionEmployee.h"

BasePlusCommissionEmployee::BasePlusCommissionEmployee(
    const string &first, const string &last, const string &ssn,
    double sales, double rate, double salary)
    // explicitly call base-class constructor
    : CommissionEmployee(first, last, ssn, sales, rate)
{
    setBaseSalary(salary);
}

void BasePlusCommissionEmployee::setBaseSalary(double salary)
{
    baseSalary = (salary < 0.0) ? 0.0 : salary;
}

double BasePlusCommissionEmployee::getBaseSalary() const
{
    return baseSalary;
}

double BasePlusCommissionEmployee::earnings() const
{
    // can access protected data of base class
    return baseSalary + (commissionRate * grossSales);
}

void BasePlusCommissionEmployee::print() const
{
    // can access protected data of base class
    cout << "base-salaried commission emplyee: " << fFirstName << ' '
         << lastName << "\nsocial security number: " << socialSecurityNumber
         << "\ngross sales: " << grossSales
         << "\ncommission rate: " << commissionRate
         << "\nbase salary: " << baseSalary;
}

Protected ์ ‘๊ทผ ์ง€์ •์ž ์‚ฌ์šฉ์˜ ์žฅ๋‹จ์ 

  • ์žฅ์ 

    • ํŒŒ์ƒ ํด๋ž˜์Šค๊ฐ€ ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„๋ฅผ ๋ฐ”๋กœ ์กฐ์ ˆ ๊ฐ€๋Šฅ
      • set | get ํ˜ธ์ถœํ•˜๋Š”๋ฐ ์†Œ๋ชจ๋˜๋Š” ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค.
      • ์ฆ‰, ์ˆ˜ํ–‰ ์†๋„๊ฐ€ ์กฐ๊ธˆ ํ–ฅ์ƒ๋œ๋‹ค.
  • ๋‹จ์ 

    • ์œ ํšจ์ฒดํฌ ๋ถˆ๊ฐ€ โ€“ set | get ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ํŒŒ์ƒ ํด๋ž˜์Šค์— ๋น„์ •์ƒ์ ์ธ ๊ฐ’์ด ํ• ๋‹น๋  ์ˆ˜ ์žˆ๋‹ค.
    • ์‹คํ–‰ ์˜์กด์ 
      • ํŒŒ์ƒ ํด๋ž˜์Šค ํ•จ์ˆ˜๋Š” ๊ธฐ๋ณธ ํด๋ž˜์Šค ๊ตฌํ˜„์— ๋” ์˜์กด์ ์ด ๋จ.
      • ๊ธฐ๋ณธ ํด๋ž˜์Šค๋ฅผ ์ˆ˜์ •ํ•˜๋ฉด ํŒŒ์ƒ ํด๋ž˜์Šค ๋˜ํ•œ ์กฐ์ ˆ ๋˜์–ด์•ผ ํ•œ๋‹ค.
        • ๋ถ€์„œ์ง€๊ธฐ ์‰ฌ์šด(fragile) ์†Œํ”„ํŠธ์›จ์–ด

8. Inheritance Hierarchy Using private Data

๊ณ„์ธต ๊ตฌ์กฐ์˜ ๊ฐœ์„ 

  • ์†Œํ”„ํŠธ์›จ์–ด ๊ณตํ•™ ๊ธฐ๋ฒ•์˜ ๊ถŒ๊ณ ๋ฅผ ๋”ฐ๋ฆ„

    • ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„๋Š” private๋กœ ์„ ์–ธ
    • public get ๊ณผ set ๋ฉค๋ฒ„ ํ•จ์ˆ˜ ์ œ๊ณต
    • ๊ธฐ๋ณธ ํด๋ž˜์Šค์—์„œ ์ƒ์†๋œ get ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŒŒ์ƒ ํด๋ž˜์Šค์—์„œ ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ private ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„์˜ ๊ฐ’์„ ์–ป๋„๋ก ํ•จ
  • ํŒŒ์ƒ ํด๋ž˜์Šค์—์„œ ์žฌ์ •์˜๋œ(override๋œ) ๋ฉค๋ฒ„ ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ ๋ฐฉ์‹

  • ํŒŒ์ƒ ํด๋ž˜์Šค ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„œ๋Š” ๊ทธ ํ•จ์ˆ˜ ์ด๋ฆ„๋งŒ์œผ๋กœ๋Š” ์žฌ์ •์˜๋œ ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•จ

  • ๋”ฐ๋ผ์„œ, ๊ฐ™์€ ์ด๋ฆ„์˜ ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ธฐ๋ณธ ํด๋ž˜์Šค์ด๋ฆ„::ํ•จ์ˆ˜ ์ด๋ฆ„๊ณผ ๊ฐ™์ด ํ˜ธ์ถœํ•ด์•ผ ํ•จ

CommissionEmployee ํด๋ž˜์Šค ๊ฐœ์„  (์ตœ์ข…๋ฒ„์ „)

CommissionEmployee.h

#include <iostream>
using std::cout;

#include "CommissionEmployee.h"

// constructor
CommissionEmployee::CommissionEmployee(
    const string &first, const string &last, const string &ssn,
    double sales, double rate)
    : firstName(first), lastName(last), socialSecurityNumber(ssn)
{
    setGrossSales(sales);
    setCommissionRate(rate);
}

void CommissionEmployee::setFirstName(const string &first)
{
    firstName = first;
}

string CommissionEmployee::getFirstName() const
{
    return firstName;
}

void CommissionEmployee::setLastName(const string &last)
{
    lastName = last;
}

string CommissionEmployee::getLastName() const
{
    return lastName;
}

void CommissionEmployee::setSocialSecurityNumber(const string &ssn)
{
    socialSecurityNumber = ssn;
}

string CommissionEmployee::getSocialSecurityNumber() const
{
    return socialSecurityNumber;
}

void CommissionEmployee::setGrossSales(double sales)
{
    grossSales = (sales < 0.0) ? 0.0 : sales;
}

double CommissionEmployee::getGrossSales() const
{
    return grossSales;
}

void CommissionEmployee::setCommissionRate(double rate)
{
    commissionRate = (rate > 0.0 && rate < 1.0) ? rate : 0.0;
}

double CommissionEmployee::getCommissionRate() const
{
    return commissionRate;
}

double CommissionEmployee::earnings() const
{
    return getCommissionRate() * getGrossSales();
}

void CommissionEmployee::print() const
{
    cout << "commission employee: " << getFirstName() << ' ' << getLastName()
         << "\nsocial security number: " << getSocialSecurityNumber()
         << "\ngross sales: " << getGrossSales()
         << "\ncommission rate: " << getCommissionRate();
}

BasePlusCommissionEmployee.cpp

#include <iostream>
using std::cout;

#include "BasePlusCommissionEmployee.h"

BasePlusCommissionEmployee::BasePlusCommissionEmployee(
    const string &first, const string &last, const string &ssn,
    double sales, double rate, double salary)
    // explicitly call base-class constructor
    : CommissionEmployee(first, last, ssn, sales, rate)
{
    setBaseSalary(salary);
}

void BasePlusCommissionEmployee::setBaseSalary(double salary)
{
    baseSalary = (salary < 0.0) ? 0.0 : salary;
}

double BasePlusCommissionEmployee::getBaseSalary() const
{
    return baseSalary;
}

double BasePlusCommissionEmployee::earnings() const
{
    // can access protected data of base class
    return getBaseSalary() + CommissionEmployee::earnings();
}

void BasePlusCommissionEmployee::print() const
{
    // can access protected data of base class
    cout << "base-salaried ";

    // invoke CommissionEmployee's print function
    CommissionEmployee::print();

    cout << "\nbase salary: " << getBaseSalary();
}

์„ค๊ณ„๋œ ํด๋ž˜์Šค ํ™œ์šฉ (driver)

#include <iostream>
#include <iomanip>

using namespace std;

#include "BasePlusCommissionEmployee.h"

int main()
{
    // instantiate BasePlusCommissionEmployee object
    BasePlusCommissionEmployee
        employee("Bob", "Lewis", "333-33-3333", 5000, .04, 300);

    cout << fixed << setprecision(2);

    cout << "Employee information obtained by get function: \n"
         << "\nFirst name is " << employee.getFirstName()
         << "\nLast name is " << employee.getLastName()
         << "\nsocial security number is " << employee.getSocialSecurityNumber()
         << "\nGross sales is " << employee.getGrossSales()
         << "\ncommission rate is " << employee.getCommissionRate()
         << "\nBase salary is " << employee.getBaseSalary() << endl;

    employee.setGrossSales(1000);

    // employee.setGrossSales(8000);
    // employee.setCommissionRate(.1);

    cout << "\nUpdated employee information ouput bt print function: \n"
         << endl;
    employee.print();

    cout << "\n\nEmployee's earning: $" << employee.earnings() << endl;

    return 0;
}

์„ค๊ณ„๋œ ํด๋ž˜์Šค ํ™œ์šฉ (์‹คํ–‰ ๊ฒฐ๊ณผ)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 8 31 03

9. ์ƒ์† ๊ตฌ์กฐ์—์„œ ์ƒ์„ฑ์ž, ์†Œ๋ฉธ์ž์˜ ์‹คํ–‰ ์ˆœ์„œ

ํŒŒ์ƒ ํด๋ž˜์Šค ๊ฐ์ฒด์˜ ์ƒ์„ฑ ๊ณผ์ •

  • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž์™€ ์†Œ๋ฉธ์ž๋Š” ํŒŒ์ƒํด๋ž˜์Šค์— ์ƒ์†๋˜์ง€ ์•Š๋Š”๋‹ค.
  • ํŒŒ์ƒ ํด๋ž˜์Šค ๊ฐ์ฒด์˜ ์ƒ์„ฑ ๊ณผ์ •
    • ์—ฐ์‡„์ ์ธ ์ƒ์„ฑ์ž ํ˜ธ์ถœ/์‹คํ–‰/๋ฆฌํ„ด ๋งค์ปค๋‹ˆ์ฆ˜
      • ํŒŒ์ƒํด๋ž˜์Šค ์ƒ์„ฑ์ž๋Š” ๊ธฐ๋ณธ ํด๋ž˜์Šค ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.
        • ๋ช…์‹œ์ (explicitly) ํ˜น์€ ์•”์‹œ์ (implicitly)
      • ์ตœ์ƒ์œ„ ๋‹จ๊ณ„์˜ ๊ธฐ๋ณธ ํด๋ž˜์Šค
        • ๋งˆ์ง€๋ง‰์œผ๋กœ ์ƒ์„ฑ์ž๊ฐ€ ํ˜ธ์ถœ๋จ
        • ์ฒ˜์Œ์œผ๋กœ ์ƒ์„ฑ์ž ์‹คํ–‰์„ ๋งˆ์น˜๊ณ  ๋ฆฌํ„ด
      • CommissionEmployee/BasePlusCommissionEmployee ๊ณ„์ธต
        • CommissionEmployee: ๋งˆ์ง€๋ง‰์— ์ƒ์„ฑ์ž ํ˜ธ์ถœํ•˜๊ณ  ์ฒ˜์Œ์œผ๋กœ ์ƒ์„ฑ์ž ์‹คํ–‰์„ ๋งˆ์นจ
      • ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„ ์ดˆ๊ธฐํ™”
        • ๊ฐ ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๋Š” ํŒŒ์ƒ ํด๋ž˜์Šค์˜ member initializer์—์„œ ํ˜ธ์ถœ๋˜์–ด ์ž์‹ ์˜ ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„๋ฅผ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.

ํŒŒ์ƒ ํด๋ž˜์Šค ๊ฐ์ฒด์˜ ์†Œ๋ฉธ ๊ณผ์ •

  • ์—ฐ์‡„์  ์†Œ๋ฉธ์ž ํ˜ธ์ถœ
    • ์—ฐ์‡„์  ์ƒ์„ฑ์ž ๊ตฌ์กฐ์˜ ๋ฐ˜๋Œ€ (ํ•จ์ˆ˜์˜ body์˜ ์‹คํ–‰์ˆœ์„œ)
    • ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ์†Œ๋ฉธ์ž๊ฐ€ ์ฒ˜์Œ ํ˜ธ์ถœ ๋ฐ ์‹คํ–‰
    • ๊ทธ ๋‹ค์Œ ์ƒ์œ„ ๊ธฐ๋ณธ ํด๋ž˜์Šค ์†Œ๋ฉธ์ž ํ˜ธ์ถœ ๋ฐ ์‹คํ–‰
      • ์ตœ์ข… ๊ธฐ๋ณธ ํด๋ž˜์Šค์— ๋„์ฐฉํ•  ๋•Œ๊นŒ์ง€ ๊ณ„์†
      • ๋ฆฌํ„ด ์ˆœ์„œ๋Š” ๊ธฐ๋ณธ ํด๋ž˜์Šค -> ํŒŒ์ƒ ํด๋ž˜์Šค์˜ ์ˆœ์„œ
        • ๊ฐ€์žฅ ํ•˜์œ„์˜ ํŒŒ์ƒ ํด๋ž˜์Šค ์†Œ๋ฉธ์ž๊ฐ€ ์ตœ์ข…์ ์œผ๋กœ ๋ฆฌํ„ดํ•˜๋ฉด ๋ฉ”๋ชจ๋ฆฌ์—์„œ ๊ฐ์ฒด๊ฐ€ ์ œ๊ฑฐ๋œ๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 8 36 49

์ƒ์„ฑ์ž ๋ฐ ์†Œ๋ฉธ์ž ํ˜ธ์ถœ ์ˆœ์„œ ์˜ˆ์ œ

CommissionEmployee.cpp

#include <iostream>
using std::cout;

#include "CommissionEmployee.h"

// constructor
CommissionEmployee::CommissionEmployee(
    const string &first, const string &last, const string &ssn,
    double sales, double rate)
    : firstName(first), lastName(last), socialSecurityNumber(ssn)
{
    setGrossSales(sales);
    setCommissionRate(rate);

    cout << "CommissionEmployee constuctor: " << endl;
    print();
    cout << "\n\n";
}

// destructor
CommissionEmployee::~CommissionEmployee()
{
    cout << "CommissionEmployee desturctor: " << endl;
    print();
    cout << "\n\n";
}

void CommissionEmployee::setFirstName(const string &first)
{
    firstName = first;
}

string CommissionEmployee::getFirstName() const
{
    return firstName;
}

void CommissionEmployee::setLastName(const string &last)
{
    lastName = last;
}

string CommissionEmployee::getLastName() const
{
    return lastName;
}

void CommissionEmployee::setSocialSecurityNumber(const string &ssn)
{
    socialSecurityNumber = ssn;
}

string CommissionEmployee::getSocialSecurityNumber() const
{
    return socialSecurityNumber;
}

void CommissionEmployee::setGrossSales(double sales)
{
    grossSales = (sales < 0.0) ? 0.0 : sales;
}

double CommissionEmployee::getGrossSales() const
{
    return grossSales;
}

void CommissionEmployee::setCommissionRate(double rate)
{
    commissionRate = (rate > 0.0 && rate < 1.0) ? rate : 0.0;
}

double CommissionEmployee::getCommissionRate() const
{
    return commissionRate;
}

double CommissionEmployee::earnings() const
{
    return getCommissionRate() * getGrossSales();
}

void CommissionEmployee::print() const
{
    cout << "commission employee: " << getFirstName() << ' ' << getLastName()
         << "\nsocial security number: " << getSocialSecurityNumber()
         << "\ngross sales: " << getGrossSales()
         << "\ncommission rate: " << getCommissionRate();
}

BasePlusCommissionEmployee.cpp

#include <iostream>
using std::cout;

#include "BasePlusCommissionEmployee.h"

BasePlusCommissionEmployee::BasePlusCommissionEmployee(
    const string &first, const string &last, const string &ssn,
    double sales, double rate, double salary)
    // explicitly call base-class constructor
    : CommissionEmployee(first, last, ssn, sales, rate)
{
    setBaseSalary(salary);

    cout << "BasePlusCommissionEmployee constructor: " << endl;
    print();
    cout << "\n\n";
}

// destructor
BasePlusCommissionEmployee::~BasePlusCommissionEmployee()
{
    cout << "BasePlusCommissionEmployee destructor: " << endl;
    print();
    cout << "\n\n";
}

void BasePlusCommissionEmployee::setBaseSalary(double salary)
{
    baseSalary = (salary < 0.0) ? 0.0 : salary;
}

double BasePlusCommissionEmployee::getBaseSalary() const
{
    return baseSalary;
}

double BasePlusCommissionEmployee::earnings() const
{
    // can access protected data of base class
    return getBaseSalary() + CommissionEmployee::earnings();
}

void BasePlusCommissionEmployee::print() const
{
    // can access protected data of base class
    cout << "base-salaried ";

    // invoke CommissionEmployee's print function
    CommissionEmployee::print();

    cout << "\nbase salary: " << getBaseSalary();
}

driver

#include <iostream>
#include <iomanip>

using namespace std;

#include "BasePlusCommissionEmployee.h"

int main()
{
    cout << fixed << setprecision(2);

    { // begin new scope
        CommissionEmployee employee1("Bob", "Lewis", "111-11-1111", 1000, .01);

    } // end scope

    cout << endl;
    BasePlusCommissionEmployee employee2("Peter", "Lee", "221-12-2222", 2000, .02, 222);

    cout << endl;
    BasePlusCommissionEmployee employee3("JJang-gu", "Shin", "331-13-3113", 3000, .03, 333);

    cout << endl;
    return 0;
}

์‹คํ–‰๊ฒฐ๊ณผ

CommissionEmployee constuctor:
commission employee: Bob Lewis
social security number: 111-11-1111
gross sales: 1000.00
commission rate: 0.01

CommissionEmployee desturctor:
commission employee: Bob Lewis
social security number: 111-11-1111
gross sales: 1000.00
commission rate: 0.01


CommissionEmployee constuctor:
commission employee: Peter Lee
social security number: 221-12-2222
gross sales: 2000.00
commission rate: 0.02

BasePlusCommissionEmployee constructor:
base-salaried commission employee: Peter Lee
social security number: 221-12-2222
gross sales: 2000.00
commission rate: 0.02
base salary: 222.00


CommissionEmployee constuctor:
commission employee: JJang-gu Shin
social security number: 331-13-3113
gross sales: 3000.00
commission rate: 0.03

BasePlusCommissionEmployee constructor:
base-salaried commission employee: JJang-gu Shin
social security number: 331-13-3113
gross sales: 3000.00
commission rate: 0.03
base salary: 333.00


BasePlusCommissionEmployee destructor:
base-salaried commission employee: JJang-gu Shin
social security number: 331-13-3113
gross sales: 3000.00
commission rate: 0.03
base salary: 333.00

CommissionEmployee desturctor:
commission employee: JJang-gu Shin
social security number: 331-13-3113
gross sales: 3000.00
commission rate: 0.03

BasePlusCommissionEmployee destructor:
base-salaried commission employee: Peter Lee
social security number: 221-12-2222
gross sales: 2000.00
commission rate: 0.02
base salary: 222.00

CommissionEmployee desturctor:
commission employee: Peter Lee
social security number: 221-12-2222
gross sales: 2000.00
commission rate: 0.02

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 8 56 00

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 8 56 26

10. Public, protected and private Inheritance

Public ์ƒ์†, Protected ์ƒ์† ๋ฐ private ์ƒ์†

Public ์ƒ์†

  • ๊ธฐ๋ณธ ํด๋ž˜์Šค public ๋ฉค๋ฒ„
    • ํŒŒ์ƒ ํด๋ž˜์Šค public ๋ฉค๋ฒ„
  • ๊ธฐ๋ณธ ํด๋ž˜์Šค protected ๋ฉค๋ฒ„
    • ํŒŒ์ƒ ํด๋ž˜์Šค protected ๋ฉค๋ฒ„
  • ๊ธฐ๋ณธ ํด๋ž˜์Šค private ๋ฉค๋ฒ„๋Š” ์ง์ ‘ ์ ‘๊ทผ ๋ถˆ๊ฐ€๋Šฅ
    • ๊ธฐ๋ณธ ํด๋ž˜์Šค์˜ public ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ ๊ฐ€๋Šฅ

protected ์ƒ์†

  • ๊ธฐ๋ณธ ํด๋ž˜์Šค public ๊ณผ protected ๋ฉค๋ฒ„
    • ํŒŒ์ƒ ํด๋ž˜์Šค protected ๋ฉค๋ฒ„

private ์ƒ์†

  • ๊ธฐ๋ณธ ํด๋ž˜์Šค public ๊ณผ protected ๋ฉค๋ฒ„
    • ํŒŒ์ƒ ํด๋ž˜์Šค private ๋ฉค๋ฒ„

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 8 58 20

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 8 58 35

ํŒŒ์ƒ ํด๋ž˜์Šค์—์„œ์˜ ๊ธฐ๋ณธ ํด๋ž˜์Šค ๋ฐ์ดํ„ฐ ๋ฉค๋ฒ„ ์ ‘๊ทผ์„ฑ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-06 แ„‹แ…ฉแ„’แ…ฎ 8 59 02