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'm in the middle of writing a Flash application which has multilingual support.
Greetings, I'm in the progress of writing a web server script that lets you
greetngs, i am trying to learn Java and Swing by writing a simple game
Greetings Friends, I am trying to overlay the simple 2D game I am developing
Greetings Everyone. I'm currently writing a multi-language programe in C, C++ and fortran on
Greetings. I'm writing a web application that is supposed to connect to a SQL
Greetings, Overflowers! I am writing an application in PHP that will allow for editing
I have a little problem with a class I am currently writing a save
Greetings Community! <object id=myExperienceXXXXXXXX class=BrightcoveExperience> <param name=bgcolor value=#FFFFFF /> <param name=width value=448 /> <param
Greetings, I've been writing some nasty code to support the undo/redo of deletion of

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.