This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SilentGigantosaurusDecorator : IGigantosaurus | |
{ | |
protected readonly IGigantosaurus gigantosaurus; | |
public SilentGigantosaurusDecorator(IGigantosaurus gigantosaurus) | |
{ | |
this.gigantosaurus = gigantosaurus; | |
} | |
public string Roar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void AdapterExample() | |
{ | |
var triceratops = new Triceratops(); | |
var child = ChildCreator.CreateChild(new TriceratopsToMammalAdapter(triceratops)); | |
child.Cry(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DesignPatterns.Adapter | |
{ | |
public interface IChild | |
{ | |
void Cry(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace DesignPatterns.Adapter | |
{ | |
public class TriceratopsToMammalAdapter : IMammal | |
{ | |
private readonly Triceratops triceratops; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DesignPatterns.Adapter | |
{ | |
public class TriceratopsEgg | |
{ | |
public IChild Hatch() | |
{ | |
return new TriceratopsChild(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace DesignPatterns.Adapter | |
{ | |
public interface IEgg | |
{ | |
IChild Hatch(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace DesignPatterns.Adapter | |
{ | |
public class Triceratops | |
{ | |
public TriceratopsEgg LayEgg() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace DesignPatterns.Adapter | |
{ | |
public interface IMammal | |
{ | |
IChild GiveBirth(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace DesignPatterns.Adapter | |
{ | |
public static class ChildCreator | |
{ | |
public static IChild CreateChild(IMammal mammal) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void DecoratorExample() | |
{ | |
var gigantosaurus = new Gigantosaurus(); | |
Console.WriteLine(gigantosaurus.Roar()); | |
var loudGigantosaurus = new LoudGigantosarusDecorator(gigantosaurus); | |
var extraLoudGigantosaurus = new ExtraLoudGigantosaurusDecorator(loudGigantosaurus); | |
Console.WriteLine(extraLoudGigantosaurus.Roar()); |
NewerOlder