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

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]이거나 여기에서 파생된 것이어야 합니다.

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

"""summary
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 getdescription(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def getdescription(self) -> str:
def get_description(self) -> str:

으로 끊어주면 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 피드백 감사합니다

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

Args:
None

Returns:
None
"""

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

Args:
None

Returns:
None
"""
Copy link
Member

Choose a reason for hiding this comment

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

input이나 return이 없는 경우, 작성하지 않는 것을 표준으로 하겠습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 확인했습니다 다음 커밋 시 반영하겠습니다.



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

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

Args:
None

Returns:
None
"""
return "Espresso"

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

Args:
None

Returns:
None
"""
return 1.99


class HouseBlend(Beverage):
"""summary
Copy link
Member

Choose a reason for hiding this comment

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

summary 단어 제거 부탁합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 알겠습니다!

Description:
Beverage 중 Espresso 클래스
"""

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

Args:
None

Returns:
description
"""
return "HouseBlend"

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

Args:
None

Returns:
cost
"""
return 0.89
93 changes: 93 additions & 0 deletions src/cafeordersimulator/condiment.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 typing import Any

from beverage import Beverage


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

def __init__(self, bevarage: Beverage) -> None:
"""상속받는 클래스에 따라 구현

Args:
None

Returns:
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.

검색 키워드 : 프로퍼티

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

Args:
None

Returns:
None
"""
return self._beverage

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

Args:
None

Returns:
None
"""
return self._beverage.getdescription()

def cost(self) -> Any:
"""summary
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:
None
"""
return self._beverage.cost()


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

def getdescription(self) -> Any:
"""summary
Description:
설명을 덧붙이는 함수
"""
return self.beverage.getdescription() + ", 모카"

def cost(self) -> Any:
"""summary
Description:
cost 계산시 0.2를 더해준다.
"""
return self.beverage.cost() + 0.20
34 changes: 34 additions & 0 deletions src/cafeordersimulator/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
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 진행함수
Args :
None
Returns :
None
"""
bevarage = Espresso()
print(bevarage.getdescription() + " $" + str(bevarage.cost()))

beverage2 = HouseBlend()
beverage2 = Mocha(beverage2)
print(beverage2.getdescription() + " $" + str(beverage2.cost()))


if __name__ == "__main__":
main()