Responsibilities of these classes

I have a class "Order Order". It contains information about one purchase order. I have a DAO class for database methods.

Where should the responsibility be for the methods that will load and update the purchase order?

If the PurchaseOrder class has the ".update", "insert", "delete" and ".load" methods that use the DAO class directly or the PurchaseOrder class does not know the DAO methods and has the POController class that controls these interactions?

The user will only work with one PurchaseOrder at a time.

Thank!

+3
source share
8 answers

. , , , .

, , , .

+4

, PurchaseOrder DAO , factory.

+1

, , . 1985 . ( , ), , 5, 10, 15 .

, API, - . , .

, . , , , .

0

PurchaseOrder DAO. purchaseOrder . , , / PurchaseOrder DAO. . , - () , / PurchaseOrders, , .

0

:


: Persistance -
, DAO .
: DAO, Factory. : . , List Search: , , . , .
: . , . , .

,


: , , , , DAO. Utility, .
: Factory DAO, .
: , . Factory.
: API.
:

PurchaseOrder po;
PurchaseOrderController poc;
poc = PurchaseOrderControllerFactory.Instance.Create();
po = poc.GetPurchaseOrder(42);
// do stuff
poc.SavePurchaseOrder(po);

.


: - . , .
. ( ). , . DAO Factory, , , .
, PurchaseOrder - DTO, . .
:

// It could be a factory if needed.
PurchaseOrderSystem pos = new PurchaseOrderSystem(); 

List<PurchaseOrder> transacted;
transacted = pos.TransactPurchaseOrders(john, 23);

// Show transacted purchase orders or whatever...
0

"-" (PurchaseOrder) / . .., , -, .

-1

, . , PurchaseOrder, .

-1

, , , , , . , ? , PO. , , .

: , () PO DAO? , , DAO. DAO , , , PO . , .

Another thing to think about is the rest of the structure. Where does the save / load start from? If you are going to do a lot of manipulations with the software (save, load, print, send by client), then it probably makes sense to have a controller that performs all these functions, and does not integrate the functionality into the PO class. This gives you the advantage that you can add PO operations without changing the PO class.

-1
source

Source: https://habr.com/ru/post/1697862/


All Articles