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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:22:04+00:00 2026-06-14T16:22:04+00:00

I have some common behaviour in several entities belonging to different aggregates, that I’d

  • 0

I have some common behaviour in several entities belonging to different aggregates, that I’d like to factor in an abstract class.

Is there any drawback to have entities in different aggregates inherit from a common abstract class?


Use case

Several entities have name, description or other properties that can be translated in different languages.

For example, I would set a name with setName(language, name) and retrieve it with getName(language).

Each text in each language is stored in an object, such as:

class EntityName
{
    protected Entity entity;
    protected Language language;
    protected String text;
    protected int version;

    public EntityName(Entity entity, Language language)
    {
        this.entity = entity;
        this.language = language;
        this.version = 1;
    }

    // setText(), getText(), ...
}

For a given Entity class, EntityName is within the Entity aggregate. Only Entity can create, read from and write to EntityName, via setName() and getName().

However, classes such as EntityName, EntityDescription, OtherEntityName would all share pretty much the same code. The only part than changes is a reference to the aggregate, and therefore the constructor.

  • 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-14T16:22:05+00:00Added an answer on June 14, 2026 at 4:22 pm

    There isn’t much on this topic. However, have a look at this article entitled How To: Domain Driven Design

    In particular, read the section entitled Step 2 – Identify Aggregates and Aggregate Roots:

    In advanced situations, the presence of polymorphism in the class
    model can affect the aggregate boundaries as well. This occurs when
    multiple aggregate root classes all share the same base class

    If you are storing book-keeping data (id, version, create timestamp, update timestamp) that is outside the domain model proper (e.g. to support your persistence layer), I don’t see this as a problem. If, however, you are trying to reuse true business methods and attributes, you could consider replacing inheritance with composition or AOP introductions.

    Update

    After looking at the updated use case, it looks as though you are really trying to achieve code reuse rather than a true Liskov is-a relationship. Some languages better support this type of reuse with concepts such as mixins (Groovy) or traits (Scala). Assuming Java, one approach you could do is create a class and use Project Lombok’s @Delegate annotation to forward to your implementation. This has the following benefits:

    • Provides the same level of Aggregate encapulation
    • Generates the bytecode for you without all the duplication in souce
    • Allows you to save your one inheritence option for a true is-a
      relationship in the future
    • Ensures consistency across your domain

    I believe this to be purer and enables flexibility in your model. I’ve used Project Lombok on a few projects with great success. It allows you to side step some of the missing language features in Java and focus more on your domain than the necessary boilerplate code required to implement certain idioms.

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

Sidebar

Related Questions

Assume some domain and view objects (that have no common base class) public class
I have several types that share common behaviour and with same constructors and operators.
I have Spring web application. I would like to put some common piece of
Quick question about include/requre_once . I have some code that is common to a
I have a scenario where I have several classes that extend from a common
We have an MVC3 controller in which there is some 'common' work that we
I have a Client/Server application, where the Client and Server have some common tables
I have to implement a few action. Each of they have some common elements,
We are using Eclipse+CDT+SVN(Linux). How can we have some common header files in a
I have some child processes which should write some logs into a common file.

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.