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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:09:56+00:00 2026-06-05T07:09:56+00:00

I was told model an abstract container for database objects that constructs accepting a

  • 0

I was told “model an abstract container for database objects that constructs accepting a varargs of children and then exposes some children inspection functionality without code repetition”.

This hints to things like “count # of children”, “find by identifier”, etc.

For simplicity’s sake, the code below just has one field from the base abstract DatabaseObject type (i.e. name) but the real code has things like “identifier” and some complex metadata look-up gimmicks.

The idea of this is certainly useful but just looking at what I started to code makes me wanna puke: it’s gonna be a Frankenstein of entanglement if I continue along this path. Any way to make this into decent Java? Any design pattern to reference? (Composite comes to mind…)

Premise: the actual functionality to be shared is useful and indeed applicable to any potential nestable types (Schemas have Tables, Tables have Columns, CompositeIndex(es) have sub-Indexes, etc.), especially the identifier look-ups…

… but “there must be a better way”. I feel that voice inside me saying “whenever you write code like that, slap yourself in the face”.

Help 🙂

public abstract class DatabaseContainerObject<ChildType extends DatabaseObject>
    extends DatabaseObject {
  protected List<ChildType> children;
  public DatabaseContainerObject(String name, ChildType... children) {
    super(name);
    this.children = new ArrayList<ChildType>(children.length);
    this.children.addAll(Arrays.asList(children));
  }
  protected List<ChildType> getChildren() {
    return Collections.unmodifiableList(children);
  }
  ... count ...
  ... find ...
  ... sort ...
  ... remove ...
  ...
}
  • 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-05T07:09:56+00:00Added an answer on June 5, 2026 at 7:09 am

    Composite comes to mind very fast, but you should also investigate the Decorator Pattern.

    Find clearly goes recursive, but Count e.g. is very limited on leaf objects and much the same on all kind of nodes.

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

Sidebar

Related Questions

I was told that for some reason, you can't update a database schema when
I am told that the Excel object model permits a Range that is not
I have a method that will provide an array of model object. Some of
Someone told me that openGL is for graphic only, and that it's very bad
I was told that the optimal way to program in C++ is to use
I was just told that I might have to work on a project where
I was told that in Java, unchecked exceptions can be caught in a try
My superior once told me that a bad way of calling a web service
Update Well, as i was told by Stuart Charles and James Gregory, my model
Someone told me in an answer to a stackoverflow question that the two big

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.