Design Pattern Examples
Overview of object-oriented design patterns
DesignPatternExamples_csharp Namespace Reference

The namespace containing all Design Pattern Examples implemented in C#. More...

Classes

class  Adapter_Exercise
 Example of using the Adapter Pattern in C#. More...
 
class  BigResource
 Represents some big resource. In this case, a text "image" rendered as a list of strings. each entry in the list is the same width. The height of the "image" is the number of entries in the list. This image is provided by the user. More...
 
class  BigResourceManager
 Represents a manager for big resources. Also provides the class factory for the Flyweight_Class instances that are associated with a particular big resource. More...
 
class  Bridge_Exercise
 Example of using the Bridge Pattern in C#. More...
 
class  Command
 Represents an operation that can be applied to a TextObject. This class can handle two kinds of operations, one that takes no additional parameters and one that takes two additional string parameters. More...
 
class  Command_Exercise
 Example of using the Command Pattern in C#. More...
 
class  Command_TextObject
 Container for a string. Need to use a class that allows the text to be changed while the container (this class) remains constant. This way, operations can be applied to the text and the container's contents change but not the container (strings are immutable in C#; this dances around that problem). More...
 
class  Composite_Exercise
 Example of using the Composite Pattern in C#. More...
 
class  Composite_FileAccess
 Static class containing functions for accessing a hardcoded "file" and "directory" hierarchy. More...
 
class  ConsoleLogger
 Represents a logger that writes to the console window. More...
 
class  DataReaderWriter
 Represents a data reader/writer to a caller. More...
 
class  DataReaderWriterException
 Represents an error that occurred when reading or writing data in the Data reader/writer. More...
 
class  DataReaderWriterInitException
 Represents an error that occurred during initialization or shut down of the Data reader/writer. More...
 
class  DataReadWriteFunctions
 Represents some P/Invoke functions for accessing a named blocks of memory to read/write data in the Adapter_BackEnd.dll. More...
 
class  Decorator
 Represents the base class of all decorators and is responsible for handling the wrapped element being decorated. More...
 
class  Decorator_Exercise
 Example of using the Decorator Pattern in C#. More...
 
class  DeviceChain
 Represents a device chain, which is a collection of DeviceNode objects. Part of the Facade pattern example. More...
 
class  DeviceNode
 Represents a single device. Part of the Facade pattern example. More...
 
class  DirEntry
 Represents a Directory entry. More...
 
class  EnableVTModeForWindowsConsole
 Enables the virtual terminal processing mode on the current Windows Console. When the program ends, the state of the processing mode is restored to what it was before we got to it. More...
 
class  EntryInformation
 Represents an individual with a Name, Age, and Height. More...
 
class  Facade_ComplicatedSubSystem
 Represents some kind of system that contains multiple device chains. Part of the Facade pattern example. More...
 
class  Facade_ComplicatedSubSystemFactory
 Class factory for the complicated sub-system class. Part of the Facade pattern example. More...
 
class  Facade_Exercise
 Example of using the Facade Pattern in C#. More...
 
class  FileDirEntry
 Base class representing a File or Directory entry. More...
 
class  FileEntry
 Represents a File entry. More...
 
class  FileLogger
 Represents a logger to a file. More...
 
class  Flyweight_Class
 Associates a context with a big resource. More...
 
struct  Flyweight_Context
 Represents the context for an instance of the Flyweight_Class. In this case, the context includes position and velocity. More...
 
class  Flyweight_Exercise
 Example of using the Flyweight Pattern in C#. More...
 
class  Group
 Represents a single group. A group has a name and zero or more users. Users are tracked by name. More...
 
class  GroupList
 Represents a list of Groups. More...
 
class  HandlerChain
 Represents a list of handlers that all implement the IMessageHandler interface. This list can be dynamically updated and each element in the list is passed messages for processing. More...
 
class  HandlerChain_Exercise
 Example of using the HandlerChain Pattern or Chain of Responsibility pattern in C#. More...
 
interface  IDeviceNetworkHighLevel
 Represents a high level view of a complex network of device chains. A device chain can be thought of as a list of devices that can be made visible or hidden in the list but maintain the same relationship to each other regardless of visibility. More...
 
interface  IDeviceNetworkLowLevel
 Represents a network of device chains and the low level access to that network. In general, the caller should take a lock on a device chain before accessing it then release the lock when done. Part of the Facade pattern example. More...
 
interface  IEventNotifications
 Represents a Subject that takes observers implementing the IObserverNumberChanged interface. More...
 
interface  IIterator
 Represents an iterator for some type. This is a forward-only iterator in that it can only start at 0 and increment through the items until done. More...
 
interface  ILogger
 Represents an implementation of a logger object as call from the Logger class. More...
 
interface  IMemento
 Represents a single memento, a single snapshot of the state of the Memento_TextObject class as represented by the private class Memento_TextObject.Memento. More...
 
interface  IMessageHandler
 Represents a handler in a chain of handlers. All objects that participate in the HandlerChain class must implement this interface. More...
 
class  Interpreter_Class
 Representation of a simple interpreter. More...
 
class  Interpreter_Exercise
 Example of using the Interpreter Pattern in C#. More...
 
interface  INumberProducer
 Represents the Subject to the observers. This is the minimum needed by observers to get access to the data provided by the Subject class. More...
 
interface  IObserverNumberChanged
 Represents an observer to the Subject class. An observer implements this interface and then subscribes to the Subject with the interface. The observer will be called whenever a change in the number is made. More...
 
interface  IRenderElement
 Represents an element that can be rendered in text. All decorators and the core element class implement this interface. More...
 
interface  ISortEntries
 Represents a sorting strategy. More...
 
interface  IStateBehavior
 Represents a class that implements one state of the state machine. More...
 
interface  IStateContext
 Represents the context as passed to each state class. More...
 
interface  ISupportVisitors
 The interface that all element classes must implement if they are to participate in the visitor pattern. More...
 
class  ItemPair
 Represents a key/value pair where the key and value are strings. More...
 
class  Iterator
 Represents an iterator for a container by implementing the IIterator interface. More...
 
class  Iterator_Exercise
 Example of using the Iterator Pattern in C#. More...
 
class  IteratorContainer_Class
 Represents a container that offers up two kinds of iterators for the hardcoded contents. More...
 
interface  IWorkByProxy
 Represents what can be done on the proxy object. This same interface is implemented on the real object as well to ensure both have the same methods. The program accesses the proxy object only through this interface. More...
 
class  Logger
 Represents the logger object to be used in the program. More...
 
class  LoggerHelpers
 Helper functions for all loggers. More...
 
class  Mediator_Exercise
 Example of using the Mediator Pattern in C#. More...
 
class  Memento_Exercise
 Example of using the Memento Pattern in C#. More...
 
class  Memento_TextObject
 Container for a string. Need to use a class that allows the text to be changed while the container (this class) remains constant. This way, operations can be applied to the text and the container's contents change but not the container (strings are immutable in C#; this dances around that problem). More...
 
struct  Message
 Represents a message sent to the windows. A message contains a type and a position. More...
 
struct  MessagePosition
 Position of the message in global coordinates (same scope of coordinates as windows). Although this can handle negative coordinates, the example is careful to use only positive coordinates. More...
 
class  MessageWindow
 Represents a rectangular region that can handle messages directed to that region. More...
 
class  MoveCommand
 Base class that represents a move command. A move command has a name and the command character that represents the command in the initial string of movement commands. More...
 
class  MoveCommandDown
 Represents the Move Down command. More...
 
class  MoveCommandLeft
 Represents the Move Left command. More...
 
class  MoveCommandNone
 Represents the Do Nothing command. This is the Null Object for this exercise. More...
 
class  MoveCommandRight
 Represents the Move Right command. More...
 
class  MoveCommandUp
 Represents the Move Up command. More...
 
class  MoveProcessor
 Represents the processor that translates the move list into a list of MoveCommand objects then either displays them or executes them. More...
 
class  NullLogger
 Represents a logger that throws away anything sent its way. More...
 
class  NullObject_Exercise
 Example of using the Null Object Pattern in C#. More...
 
class  Observer_Exercise
 Example of using the Observer Pattern in C#. More...
 
class  ObserverForBinary
 Represents an observer that prints out the current number from the Subject in binary. More...
 
class  ObserverForDecimal
 Represents an observer that prints out the current number from the Subject in decimal. More...
 
class  ObserverForHexaDecimal
 Represents an observer that prints out the current number from the Subject in hexadecimal. More...
 
class  ObserverSubject_NumberProducer
 Represents the Subject in this example, in this case, a class that contains a single number that is updated with a call to the Update() method. Whenever Update() is called, the number is incremented and all observers are notified. The observers then fetch the current number via the INumberProducer interface. More...
 
class  OrderVisitor
 A visitor used for ordering items from various shops. The user starts with an instance of this class and a list of what they want to order. More...
 
class  Program
 Contains all the top-level Design Pattern Examples. More...
 
class  Proxy_Classes_Container
 For the purposes of this example, this class encapsulates the real class and proxy class to hide them from the rest of the example program. In a real program, the real class would be in its own assembly and separate from the proxy class. More...
 
class  Proxy_Exercise
 Example of using the Proxy Pattern in C#. More...
 
class  RedForegroundDecorator
 Represents the RedForeground decorator, which renders the wrapped content as red text. More...
 
class  State_BlockComment
 Represents being in a block comment. More...
 
class  State_Constants
 Represents constants used in the State machine. This is needed in a separate class because 1) C# requires constants to be defined inside a class or struct and 2) the constant is needed across multiple classes. More...
 
class  State_Done
 Represents being done with input. More...
 
class  State_DoubleQuotedText
 Represents being inside a double-quote string where filtering is essentially turned off until the end of the string is reached. More...
 
class  State_EndBlockComment
 Represents possibly being at the end of a block comment. More...
 
class  State_EscapedDoubleQuoteText
 Represents being in an escaped character sequence inside a double- quoted string. We don't do anything with the escaped character other than output it. Handling escaped characters allows us to more accurately detect the end of the string. More...
 
class  State_EscapedSingleQuoteText
 Represents being in an escaped character sequence inside a single- quoted string. We don't do anything with the escaped character other than output it. Handling escaped characters allows us to more accurately detect the end of the string. More...
 
class  State_Exercise
 Example of using the State Pattern in C#. More...
 
class  State_Factory
 Class factory for generating the state class instances. More...
 
class  State_LineComment
 Represents being in a line comment. More...
 
class  State_NormalText
 Represents normal text behavior. More...
 
class  State_SingleQuotedText
 Represents being inside a single-quoted string where filtering is effectively turned off until the end of the string is reached. More...
 
class  State_StartComment
 Represents the possible start of a line or block comment. More...
 
class  StateContext_Class
 Represents the state machine. This maintains the context in which the state machine runs. More...
 
class  Strategy_Exercise
 Example of using the Strategy Pattern in C#. More...
 
class  Strategy_ShowEntries_Class
 Represents a way of displaying a list of EntryInformation objects in a particular order. The order of sorting is a strategy that can be specified when the class is instantiated. The sorting strategy can be modified with a flag indicating whether the sort is reversed from normal (in this case, descending instead of ascending). More...
 
class  Strategy_SortEntries_ByAge
 Strategy for sorting the ages in ascending (or descending) order. More...
 
class  Strategy_SortEntries_ByHeight
 Strategy for sorting the heights in ascending (or descending) order. More...
 
class  Strategy_SortEntries_ByName
 Strategy for sorting the names in ascending (or descending) order. More...
 
class  Strategy_SortEntries_ClassFactory
 Class constructor for the sorting strategies. More...
 
class  Templates
 
class  TextElement
 Represents the core element that can be decorated. Note that this class implements the IRenderElement but otherwise has no knowledge of any of the decorators that might be applied. More...
 
class  UnderlineDecorator
 Represents the Underline decorator, which underlines the wrapped content. More...
 
class  User
 Represents a user with a name. More...
 
class  UserGroupMediator
 Represents the mediator between caller, users, and groups. All users and groups are identified by string name. The names are case-sensitive. More...
 
class  UserGroupsContainer
 A simple container for the user and group lists. This represents some entity external to the mediator that handles such things. More...
 
class  UserList
 Represents a list of users. More...
 
class  Village
 Represents a collection of shops that can be visited. More...
 
class  Visitor
 All visitors must implement this base class and then override one or more of the VisitXXX() methods, depending on which shop type the visitor class is interested in. More...
 
class  Visitor_Baker
 Represent a baker shop. More...
 
class  Visitor_Butcher
 Represent a butcher shop. More...
 
class  Visitor_CondimentGrocer
 Represent a condiment grocer. More...
 
class  Visitor_Exercise
 Example of using the Visitor Pattern in C#. More...
 
class  Visitor_Maker
 Represent a maker (of things). More...
 
class  Visitor_PickleGrocer
 Represent a pickle grocer. More...
 
class  Visitor_Restaurant
 Represent a restaurant shop. More...
 
class  Visitor_Shop
 Base class that all shops must implement. More...
 
class  Visitor_VegetableGrocer
 Represent a vegetable grocer. More...
 
class  WhiteBackgroundDecorator
 Represents the WhiteBackground decorator, which changes the background color of the wrapped element to white. More...
 
class  WindowRectangle
 Represents a rectangular region, with upper left and lower right coordinates. More...
 

Enumerations

enum  FileDirTypes { File , Directory }
 Represents the type of entries allowed in the hierarchy for the Composite design pattern example. More...
 
enum  DeviceTypes {
  DEVICECONTROLLER , CORE , GTE , PCH ,
  PMC
}
 Identifies the type of devices that can appear in a device chain. Part of the Facade pattern example. More...
 
enum  MessageType { Close = 0 , ButtonDown = 1 , ButtonUp }
 Type of message handled by MessageWindow. More...
 
enum  CurrentState {
  Initial , NormalText , DoubleQuotedText , SingleQuotedText ,
  EscapedDoubleQuoteText , EscapedSingleQuoteText , StartComment , LineComment ,
  BlockComment , EndBlockComment , Done
}
 Represents the current state of the state machine. More...
 

Functions

delegate void two_parameter_operation (Command_TextObject source, string argument1, string argument2)
 Delegate representing an operation applied to a TextObject using two parameters.
 
delegate void no_parameter_operation (Command_TextObject source)
 Delegate representing an operation applied to a TextObject that uses no additional arguments.
 

Detailed Description

The namespace containing all Design Pattern Examples implemented in C#.

Enumeration Type Documentation

◆ CurrentState

Represents the current state of the state machine.

Enumerator
Initial 

State before the state machine actually starts. transitions to NormalText.

NormalText 

" transitions to QuotedText, / transitions to StartComment, EOF transitions to Done

DoubleQuotedText 

\ transitions to EscapedDoubleQuoteText, " transitions to NormalText, EOF transitions to Done

SingleQuotedText 

‘’` transitions to EscapedSingleQuoteText, \ transitions to NormalText, EOF transitions to Done

EscapedDoubleQuoteText 

\ transitions to QuotedText, EOF transitions to Done

EscapedSingleQuoteText 

\ transitions to SingleQuotedText, EOF transitions to Done

StartComment 

/ transitions to LineComment, * transitions to BlockComment, EOF transitions to Done, all else transitions to NormalText

LineComment 

\\n transitions to NormalText, EOF transitions to Done

BlockComment 

* transitions to EndBlockComment, EOF transitions to Done

EndBlockComment 

/ transitions to NormalText, EOF transitions to Done, all else transitions to BlockComment

Done 

Indicates processing is done.

Definition at line 17 of file State_Class.cs.

◆ DeviceTypes

Identifies the type of devices that can appear in a device chain. Part of the Facade pattern example.

Enumerator
DEVICECONTROLLER 

device controller. This is always visible.

CORE 

Core device.

GTE 

GTE device.

PCH 

PCH device.

PMC 

PMC device.

Definition at line 15 of file Facade_ComplicatedSubSystem.cs.

◆ FileDirTypes

Represents the type of entries allowed in the hierarchy for the Composite design pattern example.

Enumerator
File 

Represents a file entry.

Directory 

Represents a directory entry that can contain other FileDirEntry components.

Definition at line 17 of file Composite_FileDirEntry.cs.

◆ MessageType

Type of message handled by MessageWindow.

Enumerator
Close 

Window is asked to close itself, generally sent by the window itself in response to a button up in a Close region. Applies only to the currently selected window.

ButtonDown 

Selects a window based on position.

ButtonUp 

Take an action on the currently selected window.

Definition at line 14 of file HandlerChain_Message_Class.cs.

Function Documentation

◆ no_parameter_operation()

delegate void no_parameter_operation ( Command_TextObject  source)

Delegate representing an operation applied to a TextObject that uses no additional arguments.

Parameters
sourceTextObject to affect

◆ two_parameter_operation()

delegate void two_parameter_operation ( Command_TextObject  source,
string  argument1,
string  argument2 
)

Delegate representing an operation applied to a TextObject using two parameters.

Parameters
sourceTextObject to affect
argument1First argument for the operation.
argument2Second argument for the operation.