Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Professional ASP.NET Design Patterns
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2012, 09:44 AM
Registered User
 
Join Date: Mar 2010
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default pg 81 why is there 2 constructors with paramaters flipped?

public ApplicationBankAccountService(
IBankAccountRepository bankRepository,
BankAccountService bankAccountService)
{
_bankRepository = bankRepository;
_bankAccountService = bankAccountService;
}
public ApplicationBankAccountService(
BankAccountService bankAccountService,
IBankAccountRepository bankRepository)
{
_bankAccountService = bankAccountService;
_bankRepository = bankRepository;
}
 
Old February 12th, 2012, 03:31 PM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default nothing

maybe because of flexibility and easy to use
__________________
happy every time, happy every where

Reza Baiat
 
Old February 24th, 2012, 09:53 AM
Registered User
 
Join Date: Mar 2010
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default

the parameters are both of the same types making it no more flexible and more confusing.
 
Old February 25th, 2012, 01:40 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile

Hi there

imagine you are writing a function named Add that adds two float and int values. how do you write it?

float Add(float a, int b){

}

or maybe

float Add(int a, float b){

}

or maybe overloaded and coupled choice:

Code:
float Add(float a, int b){
 return a+b;
}

float Add(int a, float b){
 return a+b;
}
I think the complete choice is the best. so user is not limited to pass numbers in a special order.

float x = Add(2, 2.564);
float y = Add(345.9374, 17);
__________________
happy every time, happy every where

Reza Baiat
 
Old February 25th, 2012, 05:49 AM
elbandit's Avatar
Wrox Author
 
Join Date: May 2007
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Hi guys, this is a typo I'm afraid - sorry.

Although you do touch on a topic that I will be covering in my new book. That of primitive obsession. Take this code...

Code:
decimal apply_vat(decimal price, decimal vat_rare)
{
     //logic ....
}
It would be easy to get the parameters confused when calling...

Code:
decimal price_after_vat = apply_vat(1.23, 199.99); // Whoops!
Better to use value types and make things explicit...

Code:
Money apply_vat(Money price, VatRate vat)
{
  .....
}
Or better still...

Code:
Public Class Money
{
     Money apply(VatRate vat)
     {
          // return new Money with vat applied
      }
}
This way you avoid confusion, you make the concepts of money and vat more explicit and you enable them to encapsulate behaviour.

Thoughts?

Cheers
Scott





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error following directions on page 81. rnes BOOK: Windows Phone 7 Application Development: 24 Hour Trainer 1 January 30th, 2012 06:14 PM
Error Message on Page 81 vbboyd BOOK: Professional ASP.NET MVC 3 0 October 25th, 2011 01:54 AM
Automatically add querystring paramaters to URL trancehead ASP.NET 2.0 Professional 0 July 24th, 2006 03:03 AM
multivalue paramaters are not supported diegoo BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 February 20th, 2005 02:30 AM





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