using System; using System.Collections.Generic; using System.Linq; using System.Text; // Appliance of the Strategy Pattern namespace ConsoleApplication5 { class Program { static void Main(string[] args) { Dude Earl = new Dude("Albert"); Dude Gary = new Dude("Gary"); Earl.SetMorningRitual(new CigaretteSmoker()); Gary.SetMorningRitual(new CoffeeDrinker()); Earl.WakeUp(); Gary.WakeUp(); // During the day Earl decides to give up smoking and start drinking coffee in the morning instead. Earl.SetMorningRitual(new CoffeeDrinker()); Earl.WakeUp(); Console.ReadKey(); } } class Dude { IMorningRitual _behaviour; String _name; public Dude(String MyName) { _name = MyName; } public void SetMorningRitual(IMorningRitual Behaviour) { _behaviour = Behaviour; } public void WakeUp() { Console.WriteLine(this._name + " just woke up"); _behaviour.DoMorningRitual(); } } public interface IMorningRitual { void DoMorningRitual(); } public class CigaretteSmoker : IMorningRitual { public void DoMorningRitual() { Console.WriteLine("Still sleepy but gonna smoke one anyway.. *lights cigarette\n"); } } public class CoffeeDrinker : IMorningRitual { public void DoMorningRitual() { Console.WriteLine("A morning without coffee is like something without something. Aahhh delicious!\n"); } } }
Keywords
administration
(2)
AJAX
(1)
arrays
(1)
asp
(2)
ASP.NET
(2)
assembly
(2)
automation
(1)
BCS
(1)
bindings
(1)
C#
(10)
cell click
(1)
cell value
(1)
clientside
(2)
connection string
(1)
content types
(2)
CSS
(1)
csv
(1)
datagrid
(2)
delegates
(1)
design patterns
(1)
Dialog
(4)
Dictionary
(1)
domain controller
(1)
domain member
(1)
dropdown list
(2)
endpoints
(1)
enum
(1)
error
(1)
event handlers
(1)
Excel
(1)
exporting
(1)
feature event receiver
(2)
File
(1)
formatting code
(1)
forms
(2)
Function
(1)
gac
(1)
hotfolder
(1)
HTML
(2)
inheritance
(1)
javascript
(4)
keyvalue
(1)
layoutspagebase
(1)
LINQ
(2)
lists
(3)
machine account password
(1)
moss
(1)
namespaces
(1)
ObjectDataSource
(1)
objects
(1)
office
(1)
OleDbConnection
(1)
pairs
(1)
permissions
(1)
pivot
(1)
postback
(1)
powershell
(2)
radconfirm
(1)
registry
(1)
resources
(1)
role definitions
(1)
rowclick
(1)
serialization
(2)
serverside
(4)
sharepoint
(15)
site columns
(3)
snapshot
(1)
SPList
(2)
sql
(1)
sql server
(2)
string
(1)
t-sql
(2)
Telerik
(3)
TFS
(1)
Timer
(1)
timerjob
(1)
transpose
(1)
txt
(2)
update
(1)
VBA
(2)
ViewState
(2)
Visual Studio
(1)
web.config
(1)
webparts
(4)
webservices
(1)
XDocument
(1)
xml
(2)
Monday, September 19, 2011
Appliance of Strategy Design Pattern
Here is a small example of how I used the Strategy Design Pattern to re-use specific methods
Labels:
C#,
design patterns
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment