Information Technology Reference
In-Depth Information
that you are paying some extra overhead. That overhead is worthwhile
when it's needed, but when you can avoid it, you should.
Yo u h a v e t o m a k e a n e i t h e r / o r c h o i c e w i t h d y n a m i c a n d s t a t i c i n v o c a t i o n .
Yo u c a n c r e a t e o v e r l o a d s o f t h e Wr i t e P r i c i n g I n f o r m a t i o n ( ) m e t h o d t h a t
are specific to the Product classes in your object model:
public class
Product
{
public decimal
Cost {
get
;
set
; }
public string
Name {
get
;
set
; }
public decimal
Price
{
get
{
return
Cost *
1.15M
; }
}
}
// Derived Product class:
public class
SpecialProduct
:
Product
{
public string
ReasonOnSpecial {
get
;
set
; }
// other methods elided
}
// elsewhere
public static void
WritePricingInformation(
dynamic
product)
{
Console
.WriteLine(
"The price of one {0} is {1}"
,
product.Name, product.Price);
}
public static void
WritePricingInformation(
Product
product)
{
Console
.WriteLine(
"In type safe version"
);
Console
.WriteLine(
"The price of one {0} is {1}"
,
product.Name, product.Price);
}