The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Refactoring pattern quiz number 1

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Raymond Lewallen

Posts: 312
Nickname: rlewallen
Registered: Apr, 2005

Raymond Lewallen is a .Net developer and Sql Server DBA
Refactoring pattern quiz number 1 Posted: Apr 25, 2005 9:10 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Raymond Lewallen.
Original Post: Refactoring pattern quiz number 1
Feed Title: Raymond Lewallen
Feed URL: /error.htm?aspxerrorpath=/blogs/raymond.lewallen/rss.aspx
Feed Description: Patterns and Practices, OOP, .Net and Sql
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Raymond Lewallen
Latest Posts From Raymond Lewallen

Advertisement

Here is a pattern I'm sure we all see quite a bit. Nothing wrong with it really. Small, clean, simple. However, when you take into context the fact that the following code is part of an entire program used to manage carnival rides, how would you refactor the following code? No need to post code, an explanation will do. I'll post the answer and the code in a little while.

Part of a carnival program

 

Public Class Foo

 

    Private baseTokenAmount As Int32 = 1

 

    Public Function GetNumberOfRequiredTokens(ByVal typeOfPerson As PersonType) As Int32

        Select Case typeOfPerson

            Case PersonType.Infant

                Throw New Exception("Too young to ride")

            Case PersonType.Child

                Return baseTokenAmount

            Case PersonType.Adolescent

                Return baseTokenAmount * 2

            Case PersonType.Adult

                Return baseTokenAmount * 3

            Case PersonType.Senior

                Throw New Exception("Too old to ride")

        End Select

 

    End Function

 

    Public Enum PersonType

        Infant

        Child

        Adolescent

        Adult

        Senior

    End Enum

 

End Class

 

Read: Refactoring pattern quiz number 1

Topic: Zanebug v1.5.0 Beta Released Previous Topic   Next Topic Topic: 2 exciting announcements from yours truly

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use