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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:56:51+00:00 2026-05-18T20:56:51+00:00

I am working on a web service application designed using spring framework, where I

  • 0

I am working on a web service application designed using spring framework, where I have different entity classes(ActivityA,ActivityB,ActivityC…) which inherit from a base class “activity”

Now I have written different service api’s in service layer for the base class and all the child classes. (to name, ActivityService,ActivityAService,ActivityBService,ActivityCService..)

All the methods which operate similar for each activity are put in service api of base class(ActivityService) and rest in their respective services.

I generally know which object I am working on, and I call the respective service api. But in a particular case I have the activity object(don’t know of which child class it is) and have to write a method which is different for all entity objects.

PROBLEM : Is there a way,I can call different service’s based on the entity object I have.(the object I have is of entity, not service and I cant do any hard coding to get Service object)

  • 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-18T20:56:52+00:00Added an answer on May 18, 2026 at 8:56 pm

    But in a particular case I have the activity object(don’t know of which child class it is) and have to write a method which is different for all entity objects.

    Just make the base class abstract and define an abstract method that each sub class has to implement:

    public abstract class ActivityService{
        public abstract Foo processEntity(Entity entity);
    }
    

    PROBLEM : Is there a way,I can call different service’s based on the entity object I have.(the object I have is of entity, not service and I cant do any hard coding to to )

    This is a situation you should try to avoid. Usually, you should only send an entity to a service that knows what to do with it, and not to a bunch of services, one of which is in charge. But what I’d do is use a dispatcher service that keeps a map of classes that the services are in charge of. It uses logic like this:

    private Map<Class<? extends Entity>,
        Class<? extends ActivityService>> serviceMap =
            new ConcurrentHashMap<Class<? extends Entity>,
                                  Class<? extends ActivityService>>();
    private ApplicationContext context;
    private ActivityService getServiceForEntity(Entity e){
        Class<? extends Entity> entityClass = e.getClass();
        Class<? extends ActivityService> serviceClass =
            serviceMap.get(entityClass);
        if(serviceClass==null){
            for(Map.Entry<Class<? extends Entity>,
                          Class<? extends ActivityService>> entry :
                serviceMap.entrySet()){
                if(entry.getKey().isAssignableFrom(entityClass)){
                    serviceClass = entry.getValue();
                    break;
                }
            }
            if(serviceClass==null){
                // throw a suitable exception
            }
            serviceMap.put(entityClass, serviceClass);
        }
        return context.getBean(serviceClass);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working on a spring 3 web service application and on it i
Im working on a Web-Application (MyWebApp). I have a Service-Reference to a WCF-Webservice. The
The application I am working on is using RIA Web service, stored procedures, and
I have a web service application that I deployed successfully on Apache Tomcat using
I am working on a Spring web application where I have a need to
Hi i am working on web service application in android.i need a class that
I am working on a Java Web Application that exposes a web service. This
I have been working on a BlackBerry application that consumes web services from ColdFusion
I am working on a web service servlet running on Google App Engine using
I am working on a web service project using gsoap. I am new to

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.