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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:25:44+00:00 2026-05-12T15:25:44+00:00

I sometimes end up with a class hierarchy where I have an abstract base

  • 0

I sometimes end up with a class hierarchy where I have an abstract base class with some common functionality and a couple of implementing classes that fall into two (rarely more) groups which I want to treat differently in some cases. An example would be an abstract tree node class and different branch and leaf implementations where I want to distinguish branches and leaves at some point.

These intermediate classes are then only used for “is-a” statements in flow control and they don’t contain any code, although I have had cases where they “grew” some code later.

Does that seem smelly to you? In my tree example, one alternative would be to add isLeaf() / isBranch() abstract methods to the base class and implement those on the intermediate classes, but that didn’t seem to be any better to me, really, unless I’d mean to have classes that could be multiple things at once.

  • 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-12T15:25:44+00:00Added an answer on May 12, 2026 at 3:25 pm

    In general, empty classes are a code smell.

    I agree your isLeaf or isBranch methods are a correct alternative.
    They add information about the objects , which is helpful.
    (This is because, on the super class, you can’t express that subclasses are “either leaf or branch”).


    The two methods with opposite results might also be considered as code duplication.

    You could use only one… But I would recommend return an enumerated value LEAF or BRANCH.

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

Sidebar

Related Questions

I have an ObservableCollection of class Customers that I fill from a database query.
I often find that attributes can be too large. Sometimes it feels like the
Lets say we got a code generating tool that creates thousands of C# classes,
Sometimes I start a MATLAB script and realize too late that it is going
I'm a beginner and it's hard to explain my problem: My models: class Skill
This problem has been bothering me for sometime now, I have not settled on
i need to work with 100,000 list of data. sometimes need to remove an
A simplified example of a much more complex issue... A variable is sometimes defined
I'm having an issue with ordering in Mongoid (2.0.0.beta.17 and 2.0.2)/MongoDB. Perhaps I'm just
When I need to find the first node in a TTreeView , I call

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.