Amazon VO 面试真题解析:Pizza Price Calculator(面向对象设计)

20次阅读
没有评论

Write a program that allows the user to calculate the price of a pizza. A pizza has:

  • a base
  • a size
  • toppings

Assume the system stores everything in memory, no storage required.

这道 Amazon VO 题目本质上是一个简单的面向对象设计与价格计算问题:根据披萨的 base、size 和 toppings 组合出最终价格。解题时通常会先抽象出 Pizza、Base、Size、Topping 等实体,再用枚举、字典或配置表保存各项对应的价格,最后通过组合计算总价。题目强调所有数据都只存在内存中,因此不需要数据库或持久化设计,重点在于模型拆分清晰、价格规则可扩展、代码结构易维护。

正文完
 0