oo-70-245-1

oo-70-245-1 Commit Details


Date:2014-10-20 19:54:03 (10 years 2 months ago)
Author:Natalie Adams
Branch:master
Commit:c97d40505f9484f32c5f2e651b0fec4634b43aaf
Parents: 868b43e05b4058b5fcc787726b27ff9902ae1040
Message:Adding Decorator example

Changes:

File differences

Design Pattern Examples/Decorator/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace decroatorexample
{
public interface Vechile
{
string Make { get; }
string Model { get; }
double Price { get; }
}
public class HondaCity : Vechile
{
public string Make
{
get { return "HondaCity"; }
}
public string Model
{
get { return "CNG"; }
}
public double Price
{
get { return 10000; }
}
}
public abstract class VechileDecrorator : Vechile
{
private Vechile _vechile;
public VechileDecrorator(Vechile veh)
{
_vechile = veh;
}
public string Make
{
get { return _vechile.Make; }
}
public string Model
{
get { return _vechile.Model; }
}
public double Price
{
get { return _vechile.Price; }
}
}
public class SpecialOffer : VechileDecrorator
{
public SpecialOffer(Vechile vechile)
: base(vechile)
{
}
public int DiscountPercentage { get; set; }
public string Offer { get; set; }
public double Price
{
get
{
double price = base.Price;
double percentage = DiscountPercentage / (double)100;
double res = Math.Round((price * percentage), 2);
return price - res;
}
}
}
class Program
{
static void Main(string[] args)
{
HondaCity car = new HondaCity();
Console.WriteLine("Honday City base price : {0}", car.Price);
SpecialOffer offer = new SpecialOffer(car);
offer.DiscountPercentage = 25;
offer.Offer = "25 % discount";
Console.WriteLine(" Special offer price {0} ", offer.Price);
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.06424s using 14 queries.