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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:02:04+00:00 2026-05-26T10:02:04+00:00

What is the path of least evil when dealing with polymorphism and inheritance of

  • 0

What is the path of least evil when dealing with polymorphism and inheritance of entity types in a service-oriented architecture?

A principle of SOA (as I understand it) is to have entity classes as mere data constructs, lacking in any business logic. All business logic is contained in narrow-scoped, loosely-coupled services. This means service implementations are as small as possible furthering the loose coupling, and means the entities avoid having to know about every behaviour the system may perform on them.

Due to Java’s quite baffling decision to use the declared type when deciding which overloaded method to use, any polymorphic behaviour in the service implementations is instead replaced with a series of conditionals checking object.getClass() or using instanceof. This seems rather backward in an OOPL.

Is the use of conditionals the accepted norm in SOA? Should inheritance in entities be abandoned?

UPDATE

I definitely mean overloading and not overriding.

I define SOA to mean that behaviour of the system is grouped by use case into interfaces, and then the logic for these is implemented in one class per interface, generally. As such an entity class (say Product) becomes nothing more than a POJO with getters and setters. It absolutely should not contain any business logic related to a service, because then you introduce one focal point of coupling whereby the entity class needs to know about all business processes that may ever operate on it, completely negating the purpose of a loosely-coupled SOA.

So, being that one should not embed business process-specific behaviour in an entity class, one cannot use polymorphism with these entity classes – there is no behaviour to override.

UPDATE 2

The above behaviour is more simply explained as an overloaded path is chosen at compile-time, and an overridden path at run-time.

It’d be bad practice to have a subclass of your service implementation for each subtype of the domain model class it’s acting on, so how do people get around the overloading-at-compile-time issue?

  • 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-26T10:02:05+00:00Added an answer on May 26, 2026 at 10:02 am

    It took me a while from reading this to work out what you were really asking for.

    My interpretation is that you have a set of POJO classes where when passed to a service you want the service to be able to perform different operations depending on the the particular POJO class passed to it.

    Usually I’d try and avoid a wide or deep type hierarchy and deal with instanceof etc. where the one or two cases are needed.

    When for whatever reason there has to be a wide type hierarchy I’d probably use a handler pattern kind of like below.

    class Animal {
    
    }
    class Cat extends Animal {
    
    }
    
    interface AnimalHandler {
        void handleAnimal(Animal animal);
    }
    
    class CatHandler implements AnimalHandler {
    
        @Override
        public void handleAnimal(Animal animal) {
            Cat cat = (Cat)animal;
            // do something with a cat
        }
    
    }
    
    class AnimalServiceImpl implements AnimalHandler {
        Map<Class,AnimalHandler> animalHandlers = new HashMap<Class, AnimalHandler>();
    
        AnimalServiceImpl() { 
            animalHandlers.put(Cat.class, new CatHandler());
        }
        public void handleAnimal(Animal animal) {
            animalHandlers.get(animal.getClass()).handleAnimal(animal);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am tying to retrive the last part of an path . I have
I have a Path (a star figure): <Path x:Name=NiceStar StrokeThickness=10 Stroke=#ff000000 StrokeMiterLimit=1 Data=F1 M
If I have a path, like so: c:\windows\system32\inetsrv\abc.exe And I want to make a
I need to find the path of the database (MDF) or at least the
i want to understand at least abit on how the .htaccess works. i am
I would like to have at least 2 arrays which I can create when
I'm trying to find a least-resistance path from C# to C++, and while I
I'm looking for the path of least resistance (making as few code changes as
What is the path of least resistance in getting an SBCL application running on
Assume we have a path in an undirected cyclic weighted graph. Assuming we have

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.