Created
November 13, 2024 03:49
-
-
Save hongsw/f9af800321d9212b27bee6083e194c58 to your computer and use it in GitHub Desktop.
추상화 클래스 예시 Recipe 클래스를 일반화하고, FreeRecipe와 PaidRecipe 클래스
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Recipe { | |
String title; | |
List<String> ingredients; | |
Recipe(this.title, this.ingredients); | |
// 공통으로 사용할 재료 목록 메서드 | |
void getIngredientList() { | |
print("Ingredients for $title: ${ingredients.join(', ')}"); | |
} | |
// 조리법은 각 레시피 타입에서 구체적으로 구현 | |
void prepare() { | |
print("Preparing $title..."); | |
} | |
} | |
class FreeRecipe extends Recipe { | |
FreeRecipe(String title, List<String> ingredients) : super(title, ingredients); | |
@override | |
void prepare() { | |
print("Preparing free recipe for $title..."); | |
// 무료 레시피 전용 조리법 | |
} | |
} | |
class PaidRecipe extends Recipe { | |
String videoUrl; | |
PaidRecipe(String title, List<String> ingredients, this.videoUrl) | |
: super(title, ingredients); | |
@override | |
void prepare() { | |
print("Preparing premium recipe for $title with exclusive steps..."); | |
// 유료 레시피 전용 조리법 | |
} | |
// 영상 재생 기능 | |
void playVideo() { | |
print("Playing video for $title: $videoUrl"); | |
} | |
// 재료와 조리법을 읽어주는 기능 | |
void readAloud() { | |
print("Reading aloud ingredients and instructions for $title..."); | |
} | |
} | |
void main() { | |
print("무료 레시피 객체 생성"); | |
FreeRecipe freeRecipe = | |
FreeRecipe("Basic Salad", ["Lettuce", "Tomato", "Cucumber"]); | |
freeRecipe.getIngredientList(); | |
freeRecipe.prepare(); | |
print("\n"); | |
print("유료 레시피 객체 생성"); | |
PaidRecipe paidRecipe = PaidRecipe( | |
"Gourmet Pasta", | |
["Pasta", "Olive Oil", "Garlic", "Tomato Sauce", "Parmesan"], | |
"http://video.url/gourmet_pasta"); | |
paidRecipe.getIngredientList(); | |
paidRecipe.prepare(); | |
paidRecipe.playVideo(); | |
paidRecipe.readAloud(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment