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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:48:01+00:00 2026-05-16T14:48:01+00:00

Greetings, I am writing a short simple script, but has became too crowded. Stuff

  • 0

Greetings,

I am writing a short simple script, but has became too crowded. Stuff has to do quite a few things

class Stuff

  attr_accessor :config # stores configuration
  attr_accessor :dbh    # stores database handle
  attr_accessor :logger # general logger to use

  def command_do_job_1
  end

  def command_do_job_2
  end

  def command_do_job...n

end

I know, this isn’t a proper command pattern

The issue that comes about, is that each command needs

1. Configuration
1. Logger
1. Set of parameters
n. database handles
m. supporting methods/functions

Ok, now I’m not happy, because if I put the commands into proper objects, then I’m creating a lot of configuration entries, parameters, handles, and there is a lot of supporting methods/functions I want to re-use for different commands!

Something also seams really hookey about doing this way:

class Stuff
  attr_accessor :dbh, :logger, :config

end

class Command
  attr_accessor :parent

  def initialize(parent)
    @parent = parent
  end

  def config
    @parent.config
  end

  ad-nausiem for logger, dbh, other "joint" resources etc...
end

stuff = Stuff.new
cmd = Command.new stuff # so, I can carry the same logger, dbh, configs, etc..

So, if I break out the “commands” into proper objects and do it right, I have to make some sort of “framework/services” to execute the commands in and supply, logger, dbh, config etc..

verses

If I put the commands into methods (not a command pattern then), I get to reuse all my existing resources (config, logger, database handles, etc…), but at a cost of all these functions and methods being mixed up in 1 class.

What code structure would give me a better “resource/methods/functions” usage, but also allow me to keep my code nice and simple?

This isn’t that big of a program either…

-daniel

  • 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-05-16T14:48:02+00:00Added an answer on May 16, 2026 at 2:48 pm

    One change you could make is to put the joint resources into an ExecutionContext class, and the base Command class could contain a property to house that object. Then, when the application constructs Command sub-class instances, it could populate that context property with the shared data.

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

Sidebar

Related Questions

Greetings. I am interested in writing an emulator for some old computer. However, I'd
Greetings to my revered experts! I'm writing a command line tool(similar to ls or
I'm writing a simple mail client in Perl, that uses SMTP to log in
I'm writing classes which (de)serialize to/from XML. When serializing and deserializing, the class gets
Greetings, Being new to jQuery's syntax, I find myself being a bit thrown off
Greetings! I've been fooling around (a bit) with C# and its assemblies. And so
Could anyone tell me which component in MVC pattern is responsible for writing files
Hio there Scala folks, I'm actually writing my master thesis and I have to
Elegant Solution Hey People. I'm currently working on a Project and I am thinking
I have 3 columns that are resizable. When one is made wider, the one

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.