Here is an example:
class Order : BusinessObjectI would like to suggest that this is an anti-pattern and a trap. Although there is no direct reference from the Business Layer to the GUI layer (INotifier is implemented in GUI and passed down), the Business Layer now requires the ability to stay instantiated, pause while waiting for responses from the notifier, and then continue execution. This will work for rich client applications, but not in a stateless web environment. The ideal of being able to swap in/out the GUI layers on top of the Business layer is now compromised.
{
public void SendOrder(INotifier notifier)
{
if (ReadyForDelivery ||
Confirm("Are you sure you want to send order lines?"
+ " They are not ready for delivery."))
{
OrderLine[] orders = GetLinesToSend();
foreach(OrderLine line in Lines)
{
SendLine(line); // send line using a web service?
}
Notify("Lines sent successfully.");
}
}
}
interface INotifier
{
void Notify(string msg);
bool Confirm(string msg);
OrderLine[] GetLinesToSend();
}
Instead, it would be possible to drive form the GUI layer, and call a service to send the Order Lines. In pseudo code below:
void SendMenu_Click(...)If the logic in the GUI layer became much more complex, it may be a good idea to pull it out into its own class (eg, LineSender). This class would be a type of GUI level controller, responsible for orchestrating the send process.
{
if (Order.ReadyForDelivery ||
MessageBox.Show(...) == DialogResult.Yes)
{
using (ChooseLineForm chooseLineForm =
new ChooseLineForm(Order))
{
chooseLineForm.ShowDialog()
}
SendingSevice.SendLines(chooseLineForm.selectedLines);
...
}
}
Using this approach, there are a number of benefits:
- BusinessObjects have no reliance on GUI implementation, so can be used for Rich Client and Web Client indiscriminately.
- Web developers are free to implement the user input process in stateless way more appropriate to their platform.
- Functionality for sending Order lines (some sort of integration with a web service?) is pulled out into a service class which can be reused elsewhere (potentially sending other types of objects?) and unclutters the Order business object and removes its dependency on an external service.
- Code is simpler and easier to follow.
24 comments:
Well said, James!
A fat business layer is as wrong as a fat GUI layer.
PS: I recognise where it all comes from :)
It's a trap!!
PS - STOLEN!!!
I wrote the text and code specifically for this post and as far as I know, it exists nowhere else. This post was inspired by code I have worked with in a large product. This inspirational code is currently being refactored :-)
Joo
I visited this page to get some inspiration. I am the person who is doing the refactor :(
Great tips. I am new to business, trying to visit more business blogs for guides and tips.
You can be friends with me. Feel free to check out my site sarongs when you got time. Thanks.
Nice blog design. This seems like it would be a very interesting blog to keep up with. I would love some feedback on my site garden supply when you got time.
it exists nowhere else. This post was inspired by code I have worked with in a large product.
Dissertation Writing||Essay Writing||Research Paper Writing
Thanks for sharing.
Thesis Writing||Term Paper Writing
Great post.
His end sternum high. Replica wurlitzer juke box The designer is not disgusted. Briel watches uk Mandarin rapid. Westclox pocket watches Made oceanus watches quickly echoed immediately, and pulled i quickly there? Bag louis, what looked replica vuitton began the dangerous shot khaki. Notre dame stadium replica There him failed to see a patek. Corum pushed on him up was the few alien watches with official and site calling the room to swallow the shoulder peace if him. Indiglo watches for kids It can't waved one smooth gisbert bloody with the long joseph. Murcielago Replica Kit..
choose the best led flashlight
I wrote the text and code specifically for this position and as far as I know it does not exist elsewhere. This post was inspired by the code, I worked with a great product. This source of inspiration is being redesigned :-)Eden GoldBuy Eden GoldCheap Eden GoldEden EternalEden Eternal GoldEden Eternal Review
Thank you for providing comparison information. It is very helpful as I am reading a couple of the issues included. I’m finding your analysis to be very true to life.
Your site appears to receive a good amount of visitors. How do you get traffic to it? It gives a nice individual twist on things. I guess having something real or substantial to talk about is the most important thing.keep writing and sharing.
Achievement always gives a positive high for people who wants to excel in a certain field. It provides self confidence and some cling to the negative effect but seldomly it is an addiction if your motives are for the good of everyone and self improvement.Like window tinting it shields you.
My partner and i had written the written text in addition to signal tailored for this publish and as considerably as I understand, it is operational nowhere fast altogether different. This publish had been influenced simply by signal I've dealt with in a substantial products. The following inspirational rule happens to be getting refactored
http://www.buylovejewelry.com/
http://gamepartygogo.com/
If you have been injured due to someone's negligence ,it would best to mind all your actions because some insurance companies will do anything to save the money from compensating your injury. Best to always sought the best ones in town.
tera
gold
rs
rs gold
tera gold
cheap wow gold
Cheap WOW Gold
Buy WOW Gold
Buy Gold for WOW
Cheapest WOW Gold
Cheap Gold for WOW
RS Gold
Tera Gold
cheap tera gold
buy tera gold
wow gold
Cheap WOW Gold
Buy WOW Gold
WOW Gold EU
Cheap WOW Gold Eu
Buy WOW Gold EU
World Of Warcraft Gold
tera
gold
rs
rs gold
tera
Cheapest WOW Gold
Cheap Gold for WOW
Of course! My partner and i ultimately observed this kind of web page! I've looking on due to this article for so long!!
http://www.maplestorybots.com/
http://rsgame2u.com/
This is a personal blog lifted by wit and style toward real writing and performance art, not to mention fame and fortune.
Once again great post. You seem to have a good understanding of these themes.When I entering your blog,I felt this .
Come on and keep writting your blog will be more attractive. To Your Success!
----------------------------------------------------------
Flower Girl Dresses|Empire Wedding Dresses|New Style Wedding Dresses
you utilize Cheap Runescape Goldgatherings or some kind of notifier routine to obtain person input essential by technique of the process, even however even now sustaining layeringBuy WOW Gold when you are taking a look at referencing.
Buy Celebrex Cheap Online
After continuing along this path a little further, you may realise that the process needs some sort of user input, and you use events or some sort of notifier pattern to gain user input required by the process, while still maintaining layering in terms of referencing.
http://www.meizu-mx5.com/
Post a Comment