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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:02:07+00:00 2026-06-08T01:02:07+00:00

I am trying to create an application in Java which allows for generation of

  • 0

I am trying to create an application in Java which allows for generation of large Provenance graphs from small seed graphs but I am having a little trouble figuring out the best way to design my classes.

To begin with, Provenance essentially has a graph structure, nodes and edges. I have created a Java library which acts as a mapping of the Provenance Data Model to Java Objects. This allows me to abstract my application specific information from Provenance model.

My class structure looks a little like this:

  • Graph (containing Sets of Node and Edge)
  • abstract Node (Just a String name for now)
    • Agent
    • Activity
    • Entity
    • Other subclasses of Node
  • abstract Edge
    • Generation
    • Association
    • Other subclasses of Edge

Now, what I would like to do is provide weighting on the nodes and edges which act as multipliers/saturation levels. There are a couple of ways I could use the library to achieve this aim but I’m not clear on what is the best from a development and maintainability perspective.

Firstly, I defined a Weighable interface with some simple methods such as get and set minimum and maximum weights.

Now, I could either extend each subclass Node e.g.

class WeighableAgent extends Agent implements Weighable

But then this requires an extended class for every type of node available, and required me to implement the Weighable interface at every level.

Alternatively, I could provide a mixin but it would still rely on me implementing the same functionality across each subclass.

Alternatively I could have a class that composes upon Agent, but that still requires me to implement Weighable across every composition class.

Alternatively, I could compose solely on the Node class e.g.

class WeighableNode implements Weighable {

    private Node node;

    public WeighableNode(Node node) {
        this.node = node;
    }

    etc etc...

And this would allow me to only implement Weighable in one place. However, then I lose some important information about the concrete class type from anything using WeighableNode and the only way around this that I see is to provide a method:

Node getNode();

Which I’m concerned about due to the Law Of Demeter. Furthermore, this WeighableNode will be composed upon by a PresentationNode, to help with Swing which would mean I would end up chaining calls such as:

presentationNode.getWeighableNode().getNode() instanceof Agent

Which seems very unpleasant.

One final solution which I just thought of is to compose upon Node as above and then extend WeighableNode with WeighableAgent, etc etc. This means I do not need to reimplement Weighable each time and if I know I have

instanceof WeighableAgent

then the wrapped node is an Agent.

I appreciate this is quite long but I hope that an experienced developer will very quickly see the correct design practice.

  • 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-08T01:02:09+00:00Added an answer on June 8, 2026 at 1:02 am

    Too bad Java has neither real mixins nor multiple inheritance…

    Generic wrapper

    I guess I’d use WeighableNode<NodeType extends Node> as a generic wrapper type. That way, all places which require nodes of a specific type could clearly state that fact. Its getNode method could return the correct class. And you wouldn’t end up with too many classes all over the place.

    Conversion idiom

    Even if you don’t use the above approach, the following idiom might be interesting:

    class Node {
        public T asNode(Class<T extends Node> clazz) {
            return clazz.cast(this);
        }
    }
    
    class NodeWrapper<N extends Node> {
        private N realNode;
        public T asNode(Class<T extends Node> clazz) {
            try {
                return super.asNode(clazz);
            }
            catch (ClassCastException e) {
                return realNode.asNode(clazz);
            }
        }
    }
    

    You could change the above to return null instead of throwing an exception if you prefer. The idea is that the calling code doesn’t have to worry about how to convert your node to various types. You’d e.g. simply write

    presentationNode.getNode(Agent.class)
    

    This separates implementation from interface, giving you much freedom to change things later on if the need arises. The basic Node implementation would know how to convert itself, taking care of derived classes. The NodeWrapper would add conversion using composition. You could use that as the base class for WeighableNode and your presentationNode.

    Fat interface

    You could implement the weighing stuff in Node itself, and use WeighedNode just as a tagging interface, or not at all. Not the nicest solution, but will help keep your number of classes down, and shouldn’t do any real harm except for the bit of memory consumed by the extra data. The levels of indirection required by the other schemes will probably outweight that memory requirement by far.

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

Sidebar

Related Questions

I m trying to create a desktop application using swing in java, which allows
I am trying to create a simple console based java application, which requires users
I have a java desktop application for which I am trying to create a
I'm trying to launch VB application from Java, but I'm getting runtime error: Exception
I'm trying to create a web application which will get input from system. What
I am trying to create my first GUI application using (Java + Eclipse +
I am trying to create a Debian package for a Java application. In my
I'm trying to create a Java swing application and I'm trying to use a
Im trying to create application from scratch. In new maven project i add a
I'm trying to create an application where there is a JSplitPane which contains 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.