-
-
Save markschabacker/554208 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| internal class AutomatedNoteStrategyCustomer : IsAAutomatedNoteStrategy<Customer> | |
| { | |
| private Customer _parent; | |
| public AutomatedNoteStrategyCustomer(Customer Parent) | |
| { | |
| _parent = Parent; | |
| } | |
| public string Text | |
| { | |
| get { return string.Format("Automated Note for {0}",_parent.Name); } | |
| } | |
| } | |
| } |
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| internal class AutomatedNoteStrategyInvoice : IsAAutomatedNoteStrategy<Invoice> | |
| { | |
| private Invoice _invoice; | |
| public AutomatedNoteStrategyInvoice(Invoice Parent) | |
| { | |
| _invoice = Parent; | |
| } | |
| public string Text | |
| { | |
| get { return string.Format("Automated Note cost {0}",_invoice.Cost.ToString()); } | |
| } | |
| } | |
| } |
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| public class AutomatedNoteStrategyVisitor : IIsANoteParentVisitor | |
| { | |
| public IsAAutomatedNoteStrategy AutomatedNoteStrategy { get; private set; } | |
| public void VisitInvoice(Invoice invoice) | |
| { | |
| this.AutomatedNoteStrategy = new AutomatedNoteStrategyInvoice(invoice); | |
| } | |
| public void VisitCustomer(Customer customer) | |
| { | |
| this.AutomatedNoteStrategy = new AutomatedNoteStrategyCustomer(customer); | |
| } | |
| } | |
| } |
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| public class Customer : IsANoteParent | |
| { | |
| public string Name { get { return "Customer Name"; } } | |
| public void AcceptVisitor(IIsANoteParentVisitor visitor) | |
| { | |
| visitor.VisitCustomer(this); | |
| } | |
| } | |
| } |
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| public interface IIsANoteParentVisitor | |
| { | |
| void VisitInvoice(Invoice invoice); | |
| void VisitCustomer(Customer customer); | |
| // Visit(IsANoteParent) methods go here as more classes are added | |
| } | |
| } |
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| public class Invoice : IsANoteParent | |
| { | |
| public Invoice() | |
| { | |
| Cost = .02M; | |
| } | |
| public decimal Cost { get; private set; } | |
| public void AcceptVisitor(IIsANoteParentVisitor visitor) | |
| { | |
| visitor.VisitInvoice(this); | |
| } | |
| } | |
| } |
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| public interface IsAAutomatedNoteStrategy | |
| { | |
| string Text { get; } | |
| } | |
| // In this example you don't really need the generic version of the strategy interface | |
| public interface IsAAutomatedNoteStrategy<ParentT> : IsAAutomatedNoteStrategy | |
| { | |
| } | |
| } |
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| public interface IsANoteParent | |
| { | |
| void AcceptVisitor(IIsANoteParentVisitor visitor); | |
| } | |
| } |
This file contains hidden or 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.Linq; | |
| using System.Text; | |
| namespace GenericImplementationMapping | |
| { | |
| public class Note<ParentT> where ParentT : IsANoteParent | |
| { | |
| private IsAAutomatedNoteStrategy automated_note_strategy; | |
| private ParentT _parent; | |
| public Note(ParentT parent) | |
| { | |
| _parent = parent; | |
| AutomatedNoteStrategyVisitor noteStrategyVisitor = new AutomatedNoteStrategyVisitor(); | |
| parent.AcceptVisitor(noteStrategyVisitor); | |
| this.automated_note_strategy = noteStrategyVisitor.AutomatedNoteStrategy; | |
| } | |
| public string Text { get; set; } | |
| public void SetAutomatedText() | |
| { | |
| Text = automated_note_strategy.Text; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment