开发者

How Observer pattern is better than firing SQL query at certain intervals?

开发者 https://www.devze.com 2023-03-22 07:59 出处:网络
I developed an inventory application using C#-3.5. The main MDI Form contains a status bar with information on Total Gross Amount in current month and Total Bills generated in current month. Whenever

I developed an inventory application using C#-3.5. The main MDI Form contains a status bar with information on Total Gross Amount in current month and Total Bills generated in current month. Whenever a new invoice is generated and the invoice information is saved in the database, this status information is supposed to change.

At present it changes on next application startup. I could improve it further by creating a new thread when the MDI Form loads and execute SQL Query query with the timer. But I am wo开发者_开发问答ndering whether Observer pattern could be used to notify the Status Bar when a new invoice is generated. In either case, I have to fire an SQL Query.

If an Observer pattern can be used, what are the advantages?

Edited

I want to execute a method: UpdateStatusInformation() on three scenarios:

(1) Save Invoice button is clicked on Invoice Form.

(2) Delete Invoice button is clicked on DeleteInvoice Form.

(3) Save Stock button clicked (when new stock is added) on StockEntry Form.

Can I only link via a Delegate? Please illustrate.


I don't see this scenario as a candidate for observer. You don't have anything to observe here, If you are using persisted object on the status page for status linked with database, that could be a case, which I don't see from questions description. This is database update case, should be done via polling.

will it be possible for you give some idea about layers and flow of your application. Also I could see following questions. 1. Do you have Main app and separate app for invoice entry? If yes then your status page has to poll server for changes. 2. You app is a standalone app right?

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号