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

The Archive Base Latest Questions

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

I have two classes, Task and Subtask. Subtask varies very little from Task except

  • 0

I have two classes, Task and Subtask. Subtask varies very little from Task except for one important thing, it must include a different module.

The included modules, subtask_module and task_module, both have the same methods and aliases for my purposes, but internally they function a little differently once the included module extends its methods. There is no way around this for me because I’m using a plugin.

For instance, below, you see belongs_to in Task. belongs_to is extended from the included module, however its function differs slightly based on which module I include.

class Subtask < Task
  include subtask_module 
end

class Task
  include task_module

  # methods and aliases both classes use (defined in included file) 
  # but behavior changes based on
  # included file
  belongs_to :template    
end

What is the best way to do something like this? Right now it works as it is now. But it seems bloated because there will be unused things declared in Task that I don’t need.

What is the best way?

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

    You could either turn Task into a subclass also, then have each inherit from something common (using your names from above wherever possible)

    class Task
      belongs_to :template    
    end
    
    class Subtask1 < Task
      include subtask_file 
    end
    
    # this used to be Task, now is Subtask2
    class Subtask2 < Task
      include task_file
    end
    

    Or, you move the shared functionality out to its own module, then include that, and avoid superclass / subclass altogether (I would opt for this one).

    module TaskShared
      belongs_to :template    
    end
    
    class Task
      include TaskShared
      include task_file
    end
    
    class Subtask
      include TaskShared
      include subtask_file 
    end
    

    (The belongs_to might give you difficulty. If so, try adding it in the included hook)

    module TaskShared
      def self.included(klass)
        klass.belongs_to :template
      end
    end
    

    Note that there are some circumstances where this gets sticky, such as inheriting from ActiveRecord::Base classes.

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

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can be forgiven for not looking in Quartz Display… May 16, 2026 at 1:56 pm
  • Editorial Team
    Editorial Team added an answer If you could post a link it would be nice...… May 16, 2026 at 1:56 pm
  • Editorial Team
    Editorial Team added an answer obj\x86\release is the IntermediateOutputPath for the release configuration. Your project… May 16, 2026 at 1:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have two classes. One is a management class, which stores a bunch of
I have a simple question (working with Java). I have two classes, one represents
I have two classes: Account and Operator. Account contains a list of Operators. Now,
I have a script which contains two classes. (I'm obviously deleting a lot of
Let's say I have the following two classes: public class Person { public string
I have a task, which I was able to do with the use of
I have two projects : my-lib and my-web . my-lib is built using the
I'm having trouble trying to implement a shared method/property between two classes created by
hi i am new to iphone. what i am doing is creating two classes
Summary I have written a process monitor command-line application that takes as parameters: The

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.