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

  • Home
  • SEARCH
  • 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 8552835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:30:56+00:00 2026-06-11T14:30:56+00:00

I am so obsessively OC at dividing a class or instance method and move

  • 0

I am so obsessively OC at dividing a class or instance method and move it in its own class,
and many times a simple “hello world” method will be divided into many classes.

like for example,

class MainProgram
  def hello_world
    puts "hello world"
  end
end

will be divided to

class SayHello
  def initialize
    @hello = "hello"
  end

  def hello
    @hello
  end
end

class SayWorld
  def initialize
    @world = "world"
  end

  def world
    @world
  end
end

class SayHelloWorld
  def initialize
    @hello = SayHello.new.hello
    @world = SayWorld.new.world
    @hello_world = "#{@hello} #{@world}"
  end

  def hello_world
    @hello_world
  end
end

class MainProgram
  def hello_world
    @hello_world = SayHelloWorld.new.hello_world
    @hello_world
  end
end

And sometimes it feels unnecessary. Is doing it this way any good at all?

When do I stop refactoring my code?
Is there such thing as a refactored code?

  • 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-11T14:30:57+00:00Added an answer on June 11, 2026 at 2:30 pm

    “Refactoring mode” should only be enabled when you see code duplication for code that is complex enough (or contains business logic) that it might cause problems later down the line for doing maintenance/updates; such that it would create the scenario where you might forget to update all code locations that are otherwise meant to be identical in function, resulting in inconsistent behaviour of functionality depending on code-path.

    One common rule is that once you see 3 duplications of non-trivial code, you should refactor it.

    Refactoring enables re-usability, but its not exactly the same as making reusable software components (which I think is your motivation).

    What you are doing is over-engineering your software and are basically reducing your programming language’s otherwise powerful and succinct syntax into a much simpler, more brittle and less expressive one. This is because you are creating too many abstraction layers and encapsulating basic expressions into classes.

    One useful question you should ask yourself is “What benefit do I get from turning this series of expression into a class?” e.g. “Do I need to track state?”, “Do multiple instances make sense?”, and “Do I gain or lose expressiveness? flexibility? convenience?”.

    Another way of looking at it is that refactoring is often motivated by DRY (Dont Repeat Yourself), keeping in mind that DRY is not exactly the same as wanting to create reusable software components. However, there is also YAGNI (You Aint Gonna Need It): unless you need a certain functionality in the immediate future, you probably dont need to implement it now, just stick to the most basic version that works (at least to start off with).

    Dont speculate way off into the future thinking “I want to leave all options open for later on; what if I decide to do A, what if I decide to do B, yes, yes, I’m gonna turn this simple thing into a class that lets you also do f, g and h, just in case later on I decide I need it…!”.

    So a lot of this is related to getting your software requirements and scope at a fairly stable level of finalisation before you start writing the relevant code. Knowing where the road stops helps you to estimate how much fuel you need, how to pace yourself properly, and apply resources proportionately to where they are needed most.

    Also, If you are new to programming and learning a language, you will be more likely to feel the need to shoehorn every language feature in your program even if you dont need it. As you start writing more complex, real world programs (well beyond hello world), you will get a feel for when to use what.

    Becoming aware of software antipatterns is one of the best ways to speed up this process. You are currently doing a form of “Cargo Cult Programming“

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

Sidebar

Related Questions

I have been reading obsessively in SO how to perform a date object comparison
I maintain a Delphi program which uses typed binary files as its native file
Note: I'm sorry if this is an extremely simple question but I'm somewhat obsessive
I use vectors, lists, strings and wstrings obsessively in my code. Are there any
In the never-ending search for performance (and my own bludgeoning experience), I've learnt a
I have an inner class that stores the info of the controls I'm using
This must be a common problem because I see it in many published papers
I have been writing my own library using Direct X and have hit an
I have a well-honed Control-S reflex (i.e. I obsessively save my work), but when
I'm building a small controller device that I'd like to partner with a computer.

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.