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 9063713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:04:31+00:00 2026-06-16T16:04:31+00:00

In OOP and all programming in general I know that it is a clear

  • 0

In OOP and all programming in general I know that it is a clear rule that a method should only carry out one specific task, and if another task needs to be carried out then another method should be created. My problem is this seems pointless in my situation as it is just using more code opposed to it being 1 big method.

Here are the 2 ways in which my code could be structured (one which follow standard convention, and another which doesn’t but saves code)

Scenario 1 (2 methods)

Increasing stat method

public void increaseStat(short value, string stat)
{
       switch (stat)
       {
           case "stamina":
               if (staminaCheck.Checked == true)
               {
                   stamina += value;
                   staminaText.Text = Convert.ToString(stamina);
               }
               staminaCheck.Checked = false;
               break;

//There are 5 other similar cases for different stats but to save time I removed them
       }

and decreasing stat method

public void decreaseStat(short value, string stat)
{
       switch (stat)
       {
           case "stamina":
               if (staminaCheck.Checked == true)
               {
                   stamina -= value;
                   staminaText.Text = Convert.ToString(stamina);
               }
               staminaCheck.Checked = false;
               break;

//There are 5 other similar cases for different stats but to save time I removed them
       } 

As you can see the code is exactly the same apart from 1 operation which is + instead of – . So instead of copying all the code into another method for the sake of conventions I decided to do this

Scenario 2 (1 big method which tackles increasing and decreasing)

public void alterStat(short value, string stat, bool operator)
{
       switch (stat)
       {
           case "stamina":
               if (staminaCheck.Checked == true)
               { 
                   if (Operator == true) stamina -= value;
                   else stamina += value

                   staminaText.Text = Convert.ToString(stamina);
               }
               staminaCheck.Checked = false;
               break;

//There are 5 other similar cases but to save time I removed them
       }

This way I am adding 2 extra lines into each case by adding a simple if statement, but saving a load of code being copied.

I just want you opinions on whether this would be seen as good programming practice or not.

Thank you for your time.

  • 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-16T16:04:32+00:00Added an answer on June 16, 2026 at 4:04 pm

    From my point of view, the gain of having much less duplicated code clearly far outweighs the rule of separation of concerns, particularly when it comes to code maintenance.

    A similar scenario is using an Enum as a state flag of an object. The proper OOP way would be to model each state as a seperate class in a state-hierarchy. The downside of the latter is the code you have to write to find out what state an object has, particularly if you use a Visitor pattern (which you should when using OOP).

    The rule you mentioned is especially useful if it comes to the interface of a class. If it is clearer (for the user of your class) to have IncreaseStat() and DecreaseStat() operations, instead of having a general ChangeStat(), nobody hinders you to implement a private ChangeStat() method which is called by the corresponding public methods for increasing and decreasing a stat. This way you take both advantages: Having specific operations for specific tasks while internally there is no duplicated code.

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

Sidebar

Related Questions

I'm attempting to figure out OOP Javascript, jQuery, and jQuery UI all at the
I know that in OOP you want every object (from a class) to be
One thing that I find most annoying about OOP is that whenever you need
I think C++ is one of the best known programming languages of all time,
In an object-oriented programming style does how does one tend to handle graphics? Should
First of all I have to admit that my programming skills are pretty limited
I have been using CodeIgniter all these while, and have solid foundation in OOP
I have a general OOP question. If I have the following classes in C#
Frameworks being all OOP, would it not be wise to go into frameworks without
When I took my first programming course in university, we were taught that global

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.