Skip to content
93 changes: 93 additions & 0 deletions src/cafeordersimulator/beverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""
각종 음료 관련 코드

Description:
추상클래스 Beverage를 상속받아, Espresso, HouseBlend 구현

Author:
Name: Gangmin Kim
Email: rlarkdals7@gmail.com
"""
from abc import ABCMeta, abstractmethod


class Beverage(metaclass=ABCMeta):
Copy link
Collaborator

@jonhyuk0922 jonhyuk0922 Sep 26, 2022

Choose a reason for hiding this comment

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

https://docs.python.org/ko/3/library/abc.html
: abstractmethod 이 데코레이터를 사용하려면 클래스의 메타 클래스가 [ABCMeta]이거나 여기에서 파생된 것이어야 합니다.

라고 공식문서에 적혀있습니다.

"""
Description:
다양한 Beverage들을 구현하기 위한 Abstractive class
"""

Copy link
Collaborator

@KyungHyunLim KyungHyunLim Sep 19, 2022

Choose a reason for hiding this comment

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

get_description은 abstract 메소드가 안붙어있는 이유가 있나요?

def __init__(self):
self.size = "tall"

def get_description(self) -> str:
Copy link
Collaborator

@jonhyuk0922 jonhyuk0922 Sep 26, 2022

Choose a reason for hiding this comment

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

경현 said : 해당 메서드도 abstractmethod 데코레이터가 필요할 것 같습니다.

"""
Description:
상속받는 클래스에 따라 Beverage의 이름 출력 구현
"""

def set_size(self, size) -> str:
"""
Description:
Beverage의 사이즈 지정

args :
size : Beverage의 사이즈
"""
self.size = size

def get_size(self) -> str:
"""
Description:
Beverage의 사이즈 출력 구현
"""
return self.size

@abstractmethod
def cost(self) -> float:
"""
Description:
상속받는 클래스에 따라 Beverage의 가격 출력 구현
"""


class Espresso(Beverage):
"""
Description:
Beverage 중 Espresso 클래스
"""

def get_description(self) -> str:
"""Espresso 이름 출력 구현

Returns: name of beverage
"""
return "Espresso"

def cost(self) -> float:
"""Espresso 가격 출력 구현

Returns: cost of beverage
"""
return 1.99


class HouseBlend(Beverage):
"""
Description:
Beverage 중 Espresso 클래스
"""

def get_description(self) -> str:
"""Espresso 이름 출력 구현

Returns: name of beverage
"""
return "HouseBlend"

def cost(self) -> float:
"""Espresso 가격 출력 구현

Returns: cost of beverage
"""
return 0.89
106 changes: 106 additions & 0 deletions src/cafeordersimulator/condiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""
각종 음료 관련 코드

Description:
추상클래스 Beverage를 상속받아, Espresso, HouseBlend 구현

Author:
Name: Gangmin Kim
Email: rlarkdals7@gmail.com
"""
from typing import Any

from beverage import Beverage


class CondimentDecorator(Beverage):
"""
Description:
첨가물을 나타내는 추상클래스
"""

def __init__(self, bevarage: Beverage) -> None:
super().__init__()
self._beverage = bevarage

@property
def beverage(self) -> Beverage:
Copy link
Collaborator

@jonhyuk0922 jonhyuk0922 Sep 26, 2022

Choose a reason for hiding this comment

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

추상클래스에서 propertyabstractmethod 데코레이터로 감싸진 메서드는 재정의되야 인스턴스를 생성할 수 있다고 알고있는데, CondimentDecorator를 상속받은 Mocha에서 beverage를 재정의안해주는데 인스턴스가 생성될까요?

https://docs.python.org/ko/3/library/abc.html

Copy link
Member

Choose a reason for hiding this comment

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

검색 키워드 : 프로퍼티

"""
Description:
상속받는 클래스에 따라 구현

Returns:
beverage
"""
return self._beverage

def get_description(self) -> Any:
"""
Description:
상속받는 클래스에 따라 Beverage의 이름 출력 구현

Returns:
beverage.get_description
"""
return self._beverage.get_description()

def get_size(self) -> Any:
"""
Description:
상속받는 클래스에 따라 Beverage의 사이즈 출력 구현

Returns:
beverage.get_size
"""
return self._beverage.get_size()

def cost(self) -> Any:
"""
Description:
상속받는 클래스에 따라 Beverage의 가격 출력 구현

Args:
None
Comment on lines +62 to +63
Copy link
Collaborator

Choose a reason for hiding this comment

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

이부분 제거되어도 좋을듯합니다!


Returns:
beverage.cost
"""
return self._beverage.cost()


class Mocha(CondimentDecorator):
"""
Description:
Mocha를 나타내는 클래스
"""

# def __init__(self, bevarage: Beverage) -> None:
# super().__init__()
# self._beverage = bevarage

def get_description(self) -> Any:
"""
Description:
설명을 덧붙이는 함수

Returns:
beverage의 이름 + ", 모카"
Copy link
Member

Choose a reason for hiding this comment

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

type도 같이 명시 하면 좋을 것 같습니다!

"""
return self._beverage.get_description() + ", 모카"

def cost(self) -> Any:
"""
Description:
cost 계산시 size에 따라서 cost를 계산해준다.
Returns:
beverage cost + size depends cost
Comment on lines +93 to +96
Copy link
Collaborator

Choose a reason for hiding this comment

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

Description과 Returns 사이에 공백 있고 없고 통일하면 좋을 것 같습니다.

"""
beverage_cost = self._beverage.cost()

if self._beverage.get_size() == "tall":
beverage_cost += 0.10
elif self._beverage.get_size() == "grande":
beverage_cost += 0.15
elif self._beverage.get_size() == "venti":
beverage_cost += 0.20
Comment on lines +100 to +105
Copy link
Collaborator

Choose a reason for hiding this comment

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

이부분 딕셔너리를 활용하는 건 별로일까요..?

return beverage_cost
38 changes: 38 additions & 0 deletions src/cafeordersimulator/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
cafe order test 코드

Description:
cafe order 테스트를 위한 코드

Author:
Name: Gangmin Kim
Email: rlarkdals7@gmail.com
"""

from beverage import Espresso, HouseBlend
from condiment import Mocha


def main() -> None:
"""summary
Copy link
Member

Choose a reason for hiding this comment

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

제거!

Description:
Test 진행함수
"""
bevarage = Espresso()
print(bevarage.get_description() + " $" + str(bevarage.cost()))
assert bevarage.get_description() == "Espresso"

beverage2 = HouseBlend()
beverage2 = Mocha(beverage2)
print(beverage2.get_description() + " $" + str(beverage2.cost()))
assert beverage2.get_description() == "HouseBlend, 모카"

beverage3 = HouseBlend()
beverage3.set_size("venti")
beverage3 = Mocha(beverage3)
print(beverage3.cost())
assert beverage3.cost() == 1.09


if __name__ == "__main__":
main()