Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:15:07+00:00 2026-06-16T05:15:07+00:00

I have a winform application in vb.net and am developing a Rock Paper Scissor

  • 0

I have a winform application in vb.net and am developing a Rock Paper Scissor game.

I use enum in one place and string in another to represent some an weapon type as shown below:

ENUM example:

    Imports RockPaperScissors.Weapon

    Public Class PlayerComputerRandom
    Inherits Player

    Private Enum weaponsList
        Rock
        Paper
        Scissors
    End Enum

    Public Overloads Sub pickWeapon()

        Dim randomChoice = New Random()
        Dim CompChoice As Integer = randomChoice.Next(0, [Enum].GetValues(GetType(weaponsList)).Length)

        If CompChoice = "0" Then
            pWeapon = New Rock()

        ElseIf CompChoice = "1" Then
            pWeapon = New Paper()

        Else
            pWeapon = New Scissors()

        End If


    End Sub

End Class

STRING example:

Public Class Player

    Public pWeapon As Weapon


    Public Sub pickWeapon(ByVal WeaponType As String)
        If WeaponType = "Rock" Then
            pWeapon = New Rock()

        ElseIf WeaponType = "Paper" Then
            pWeapon = New Paper()

        Else
            pWeapon = New Scissors()

        End If

    End Sub

End Class

Can you tell me the advantages and disadvantages of each approach? Im new to OOP and coding so I just want to what the issue is with this approach and what would be the better approach?

Any help would be greatly appreciated.

Many Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:15:08+00:00Added an answer on June 16, 2026 at 5:15 am

    If you are going to use strings, you should at least use constants. Using string literals everywhere is just a bad idea because you can easily type something wrong. By always using constants, at least you can avoid that issue. Secondly, by using constants, it is easy to change the string value, if you ever need to, or to find all the places in the code where the constant is used:

    Global Const RockWeapon As String = "Rock"
    Global Const PaperWeapon As String = "Paper"
    Global Const ScissorsWeapon As String = "Scissors"
    

    However, the problem still exists that it is not at all obvious, when reading the code, what all of the possible values are. This can be further alleviated by grouping all the string constants into a class so that it essentially works like an enum, like this:

    Public Class Weapons
        Public Const RockWeapon As String = "Rock"
        Public Const PaperWeapon As String = "Paper"
        Public Const ScissorsWeapon As String = "Scissors"
    End Class
    

    Then, you could use the constants like this:

    Public Sub pickWeapon(ByVal WeaponType As String)
        If WeaponType = Weapons.Rock Then
            pWeapon = New Rock()
        ElseIf WeaponType = Weapons.Paper Then
            pWeapon = New Paper()
        Else
            pWeapon = New Scissors()
        End If
    End Sub
    

    However, the code is still more confusing than it needs be, in that, when you call the pickWeapon method, all it tells you is that you need to pass it a string. So, to make it clear, you would need to add a comment that explains that you must pass one of the constants in the Weapons class.

    It’s always better, when possible, to have the code be self-documenting. When you ask for the enum, you know immediately what possible values the method expects, so there is no need to add a comment to that affect.

    Additionally, since everywhere you want to set or compare the value, you want to use the constant instead of the literal, it makes no difference to the rest of the code what that actual value is. Rock could equal “Rock”, or “ROCK”, or “Hey Look, I’m a String!”. As long as everywhere in the code uses the constant, it will still work. So, if that’s the case, then there’s really no advantage to having a string over just using an integer value in an enum.

    There are some times where a string constant does make more sense. For instance, if you are saving the value to a database, and the value in the database is more useful as a human-readable value, it may make sense to use “Rock” instead of 0. But as long as you don’t have any extenuating circumstances where you need it to be a string, I would definitely recommend sticking to using the enumeration for all of the above reasons.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a .NET application that will have both a WinForms and a Silverlight
I have developed a WinForm Application with VB.Net (VS2010) having Office 2010 Professional Installed,
I have put together a .net winform application which consumes a wcf service exposed
I have a winform application which contains a window resizable but one requirement is
I'm developing a .NET Windows Forms application. I use the model-view-presenter design pattern, supervising
I have C#.Net winform application having SQL Server Database in SQLExpress with Windows Authentication.
We're writing a .NET winform application and I'm looking for options on one of
I have a winform application in C# .NET framework 2 which I want to
I have inherited a frankenstein VB6 Converted to VB.NET winform application. This application has
I have a .Net Compact Framework WinForm application , I want to catch Application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.