-
Notifications
You must be signed in to change notification settings - Fork 0
feature/define cafe order system #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8a06af1
faf3d9b
eb71be2
170f291
91004ff
458949d
a962395
22a02cb
1a2eadd
df79f7c
c3006ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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): | ||
| """ | ||
| Description: | ||
| 다양한 Beverage들을 구현하기 위한 Abstractive class | ||
| """ | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| def __init__(self): | ||
| self.size = "tall" | ||
|
|
||
| def get_description(self) -> str: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 경현 said : 해당 메서드도 |
||
| """ | ||
| 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 | ||
| 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: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추상클래스에서
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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의 이름 + ", 모카" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| """ | ||
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이부분 딕셔너리를 활용하는 건 별로일까요..? |
||
| return beverage_cost | ||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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]이거나 여기에서 파생된 것이어야 합니다.라고 공식문서에 적혀있습니다.