Click here to Skip to main content
15,888,803 members
Articles / Programming Languages / Visual Basic

Design Your Soccer Engine, and Learn How To Apply Design Patterns (Observer, Decorator, Strategy, and Builder Patterns) - Part III and IV

Rate me:
Please Sign up or sign in to vote.
4.87/5 (70 votes)
21 Oct 2009CPOL9 min read 126K   607   144  
This article is a continuation of the previous article, and in this article, we will discuss (1) Applying the Strategy pattern to solve design problems related with 'Team' and 'TeamStrategy', and (2) Applying the Decorator pattern to solve design problems related with the 'Player'.
��'Context: The Team class
'This class encapsulates the algorithm

Public Class Team


    'Just a variable to keep the name of team
    Private teamName As String


    'A reference to the strategy algorithm to use
	Private strategy As TeamStrategy

    'ContextInterface to set the strategy
    Public Sub SetStrategy(ByVal s As TeamStrategy)
        'Set the strategy
        strategy = s
    End Sub

    'Function to play
    Public Sub PlayGame()
        'Print the team's name
        System.Console.WriteLine(" -" & teamName)
        'Play according to the strategy
        strategy.Play()
    End Sub

    'Constructor to create this class, by passing the team's
    'name

    Public Sub New(ByVal teamName As String)
        'Set the team name to use later
        Me.teamName = teamName

    End Sub

End Class ' END CLASS DEFINITION Team

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
Architect, Developer, Speaker | Wannabe GUT inventor & Data Scientist | Microsoft MVP in C#

Comments and Discussions