进销存管理系统
使用面向对象的编程思想开发(货物管理系统)
分析
这个程序中一共需要提取多少对象
角色分析
- 货物
- 管理系统
一般情况下在开发中一个对象就是一个class,一个类用一个程序文件
class Good(object):
def __init__(self, id, name, price, count, unit, type):
self.id = id
self.name = name
self.price = 0
self.count = 0
self.set_price(price)
self.set_count(count)
self.unit = unit
self.type = type
def set_price(self, price):
if price > 0:
self.price = price
else:
self.price = 0
def get_price(self):
return self.price
def set_count(self, count):
if count > 0:
self.count = count
else:
self.count = 0
def get_count(self):
return self.count
def __str__(self):
return f"{self.id},{self.name},{self.price},{self.count},{self.unit},{self.type}"
# 货物编号从000001开始
from GoodsManager.goods import Good
class ManagerSystem(object):
def __init__(self):
# 存储所有货物的列表
self.good_data = []
# 一般情况下,对一个模块中的程序入口函数
def run(self):
# 【1】加载所有的货物
# 【2】显示功能菜单
self.show_menu()
index = input("请输入操作指令:")
# 【3】根据操作指令选择对应的功能
while True:
if index == "1":
self.add_good()
pass
elif index == "2":
self.addid_good()
pass
elif index == "3":
self.update_good()
pass
elif index == "4":