简体   繁体   English

关于商业WinForms应用程序中C#OOP概述的问题-对象范围

[英]Question on overview of C# OOP in business WinForms application - scope of Object

I may have all this OO completely wrong, but here goes: 我可能所有这些OO都完全错误,但是这里有:

Ok, the scenario is a classic order entry. 好的,该场景是一个经典的订单输入。

Customer places an Order which has OrderLineItems of StockItems. 客户下了一个具有StockItems的OrderLineItems的订单。 Order is entered by Employee. 订单由员工输入。

  1. Application starts and asks for login/password 应用程序启动并要求输入登录名/密码
  2. Employee selects 'Orders' from Mainmenu form 员工从Mainmenu菜单中选择“订单”
  3. Orders forms opens.... 订单表单打开。
  4. Employee selects Customer 员工选择客户
  5. Employee selects Stock adds to OrderLineItems 员工选择将库存添加到OrderLineItems
  6. Selects second StockItem; 选择第二个StockItem; add to OrderLineItems 添加到OrderLineItems
  7. Order is committed, (stock decremented, order posted to DB, Order printed) 提交订单(库存减少,订单过帐到DB,打印订单)
  8. Employee is returned to MainMenu 员工返回MainMenu

Now with Object scope: 现在有了对象范围:

  1. Application starts and asks for login/password 应用程序启动并要求输入登录名/密码
    • Is this the best place to make objEmployee, to be kept whilst in this whole Sales application? 这是制作objEmployee的最佳位置,并保留在整个Sales应用程序中吗?
  2. Employee selects 'Orders' from Mainmenu form 员工从Mainmenu菜单中选择“订单”
  3. Orders forms opens.... 订单表单打开。
    • Make objOrderHeader, is objEmployee able to be passed in or is it created here, or re-created here. 使objOrderHeader,是否可以传入objEmployee或是否在此处创建或在此处重新创建。
  4. Employee selects Customer - adds/edits Customer details if required... 员工选择客户-如果需要,添加/编辑客户详细信息...
    • Make objCustomer 使objCustomer
  5. Employee selects Stock adds to OrderLineItems... 员工选择将库存添加到OrderLineItems ...
    • Make objStockItem and objOrderLineItem -> add to objOrderLineItems_collection 使objStockItem和objOrderLineItem->添加到objOrderLineItems_collection
  6. Selects second StockItem; 选择第二个StockItem; add to OrderLineItems... 添加到OrderLineItems ...
    • Make objStockItem and objOrderLineItem -> add to objOrderLineItems_collection 使objStockItem和objOrderLineItem->添加到objOrderLineItems_collection
  7. Order is committed, (stock decremented, order posted to DB, Order printed, Order Entered By = EmployeeID) 提交订单(减少库存,将订单过帐到DB,打印订单,输入订单= EmployeeID)
    • Once posted to Db, all objects now redundant/garbage (except objEmployee?) 一旦发布到Db,所有对象现在都是冗余/垃圾(objEmployee吗?)
  8. Employee is returned to MainMenu 员工返回MainMenu
    • Is objEmployee still valid as an object? objEmployee仍然作为对象有效吗?

I am far from an expert, but what you are describing seems to be more a procedural idea than an object oriented one. 我距离专家还很远,但是您所描述的似乎是一个过程性的想法,而不是面向对象的想法。

If you were thinking in object oriented terms you might be asking questions such as should Employee and Customer share a common Person base class that defines Name, Age and Address properties which Employee can inherit and extend by adding a Salary property and Customer could extend by adding a CreditCard property. 如果您以面向对象的方式思考,您可能会问一些问题,例如Employee和Customer是否应该共享一个通用的Person基类,该基类定义了Name,Age和Address属性,Employee可以通过添加Salary属性来继承和扩展,而Customer可以通过添加来扩展信用卡财产。

Maybe both your Employee and Customer business objects will implement an IStoreable interface that defines methods which are called when you want to save/load them to/from a Database. 也许您的Employee和Customer业务对象都将实现IStoreable接口,该接口定义当您要将它们保存到数据库或从数据库加载时调用的方法。

Perhaps you would use a CustomerPresenter class that maintains a reference to a Customer object and manages the way that it is displayed by the CustomerDetailsForm for editing. 也许您会使用CustomerPresenter类,该类维护对Customer对象的引用,并管理CustomerDetailsForm显示该对象以进行编辑的方式。

As far as object creation is concerned, I think this is something that the needs of the application dictates, but you don't want to break encapsulation by having an Employee class that is also responsible for creating Customer objects (daft example) so sometimes you will have other objects who's job it is to manage the creation of Employees and Customers at the appropriate time. 就对象创建而言,我认为这是应用程序需求所决定的,但是您不希望通过让Employee类也负责创建Customer对象的方式破坏封装(示例示例),有时您将有其他对象在适当的时间管理员工和客户的创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM