Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Professional ASP.NET Design Patterns
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET Design Patterns
This is the forum to discuss the Wrox book Professional ASP.NET Design Patterns by Scott Millett; ISBN: 978-0-470-29278-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 21st, 2010, 02:56 PM
Registered User
 
Join Date: Oct 2010
Location: Florida, USA
Posts: 5
Thanks: 4
Thanked 2 Times in 2 Posts
Default Classes in the Model interacting with each other

Scott / wrox community:

What is your feeling when 2 different model classes need to interact with each other directly? I looked in the Agathas.Storefront project and the classes within the model didn't really call other classes in the model or instantiate instances of them; only used for exposing as properties, or to use as an argument parameter.

So here is what I am getting at - let's say I have Employee and Payroll Model classes. Employee has an exposed method to provide the Employee's Pay Raise for the year, but gets this info by calling the Payroll class. Currently I make a concrete instance of Payroll from Employee, call the methods that do the calculations and get the result to expose via the Employee class. Does this create a tightly coupled situation? Should the Payroll Model class have an Interface exposing these methods, and make my Employee class work with the Interface instead? I am wondering if the Payroll class ever needs to change, I don't want the Employee class to break too.

I tried to see how you are doing this, but didn't find an exact match. Should I make Payroll implement and Interface and have Employee work with the Interface, or just allow Employee to work directly with Payroll? Or is there a better way all together to explain my simple example. Again this is all within the Model layer.

Thanks!!
Reply With Quote
The Following User Says Thank You to ATCONWAY For This Useful Post:
elbandit (November 12th, 2010)
  #2 (permalink)  
Old October 22nd, 2010, 08:31 AM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Heh Allen,

Hmm not sure I follow the example. Wouldn't PayRoll be responsible for issuing pay rises? (I am not sure of the domain as I don't get many pay rises )

Something like:

Code:
 
puiblic class PayRollSystem
{
     public void IssueAnnualPayriseTo(Employee employee, Manager authorisingManager)
     {
         // Check to see if this employee has been given a payrise this year..

         // Update employee with new salary information.
     }
 
}
Can you write some code so I can get a better understanding?

Cheers
Scott
Reply With Quote
The Following User Says Thank You to elbandit For This Useful Post:
ATCONWAY (October 22nd, 2010)
  #3 (permalink)  
Old October 22nd, 2010, 02:33 PM
Registered User
 
Join Date: Oct 2010
Location: Florida, USA
Posts: 5
Thanks: 4
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by elbandit View Post
Heh Allen,

(I am not sure of the domain as I don't get many pay rises )
Me neither , but you definitely deserve one!

On the code side, I think where I may have messed up is trying to make the pay raise a method exposed on Employee 'PayRaiseRate()' that calls payroll, where I should probably place that method solely within Payroll and have the employee object passed in. I thought at 1st it was an operation 'on' an employee (get pay raise rate on this employee instance), but I should do the inverse of that like you described.

So there really are not too many times when one Model class directly instantiates a concrete instance of another correct?
Reply With Quote
  #4 (permalink)  
Old October 26th, 2010, 04:51 AM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Quote:
So there really are not too many times when one Model class directly instantiates a concrete instance of another correct?
I guess the creation of business entities is the role of the Factory design pattern. You can see in the Basket class that it uses the BasketItemFactory To create an instance of the BasketItem class. http://aspnetdesignpatterns.codeplex.../52644#1004145
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to have multiple views interacting? ttdevelop BOOK: Professional Android 2 Application Development 2 April 7th, 2010 05:04 PM
Interacting with Word hewstone999 Access VBA 0 March 25th, 2008 11:22 AM
Web page interacting kuzbari C# 1 March 19th, 2006 01:28 PM
Interacting User Controls hugh@kmcnetwork.com ASP.NET 1.0 and 1.1 Professional 4 March 27th, 2005 06:11 AM
Interacting with Server's Desktop CCSBuz Classic ASP Professional 0 February 13th, 2005 02:26 AM



All times are GMT -4. The time now is 02:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.