Question on overview of C# OOP in business WinForms application - scope of Object
I may have all this OO completely wrong, but here goes:
Ok, the scenario is a classic order entry.
Customer places an Order which has OrderLineItems of StockItems. Order is entered by Employee.
- Application starts and asks for login/password
- Employee selects 'Orders' from Mainmenu form
- Orders forms opens....
- Employee selects Customer
- Employee selects Stock adds to OrderLineItems
- Selects second StockItem; add to OrderLineItems
- Order is committed, (stock decremented, order posted to DB, Order printed)
- Employee is returned to MainMenu
Now with Object scope:
- Application starts and asks for login/password
- Is this the best place to make objEmployee, to be kept whilst in this whole Sales application?
- Employee selects 'Orders' from Mainmenu form
- Orders forms opens....
- Make objOrderHeader, is objEmployee able to be passed in or is it created here, or re-created here.
- Employee selects Customer - adds/edits Customer details if required...
- Make objCustomer
- Employee selects Sto开发者_运维技巧ck adds to OrderLineItems...
- Make objStockItem and objOrderLineItem -> add to objOrderLineItems_collection
- Selects second StockItem; add to OrderLineItems...
- Make objStockItem and objOrderLineItem -> add to objOrderLineItems_collection
- Order is committed, (stock decremented, order posted to DB, Order printed, Order Entered By = EmployeeID)
- Once posted to Db, all objects now redundant/garbage (except objEmployee?)
- Employee is returned to MainMenu
- Is objEmployee still valid as an object?
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.
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.
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.
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.
精彩评论