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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:25:59+00:00 2026-05-19T04:25:59+00:00

I know there is an invoke function that does the stuff, I am overall

  • 0

I know there is an invoke function that does the stuff, I am overall interested in the “correctness” of using such a behavior.
My issue is this:
I have a Service Object witch contains methods which I consider services.
What I want to do is alter the behavior of those services without later intrusion.
For example:

class MyService {

      public ServiceResponse ServeMeDonuts() {
      do stuff...
      return new ServiceResponse();

}

after 2 months I find out that I need to offer the same service to a new client app and I also need to do certain extra stuff like setting a flag, or make or updating certain data, or encode the response differently. What I can do is pop it up and throw down some IFs. In my opinion this is not good as it means interaction with tested code and may result in un wanted behaviour for the previous service clients.

So I come and add something to my registry telling the system that the “NewClient” has a different behavior. So I’ll do something like this:

public interface Behavior {
    public void preExecute();
    public void postExecute();
}

public class BehaviorOfMyService implements Behavior{
      String method;
      String clientType;

      public void BehaviorOfMyService(String method,String clientType) {
              this.method = method;
              this.clientType = clientType;
      }

      public void preExecute() {

        Method preCall = this.getClass().getMethod("pre" + this.method + this.clientType);
        if(preCall != null) {
            return preCall.invoke();
        } 
           return false;
      }

      ...same for postExecute();
     public void preServeMeDonutsNewClient() {
           do the stuff...
     }
}

when the system will do something like this

if(registrySaysThereIs different behavior set for this ServiceObject) {
      Class toBeCalled = Class.forName("BehaviorOf" + usedServiceObjectName);
      Object instance = toBeCalled.getConstructor().newInstance(method,client);
      instance.preExecute();
      ....call the service...
      instance.postExecute();
      ....
}

I am not particularly interested in correctness of code as in correctness of thinking and approach. Actually I have to do this in PHP, witch I see as a kind of Pop music of programming which I have to “sing” for commercial reasons, even though I play POP I really want to sing by the book, so putting aside my more or less inspired analogy I really want to know your opinion on this matter for it’s practical necessity and technical approach.

Thanks

  • 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-19T04:26:00+00:00Added an answer on May 19, 2026 at 4:26 am

    Nice case to apply Aspect Oriented Programming. With AOP you can attach aspects to events or methods in order to process extra logic before or after the event.

    There are good examples of AOP here and also examples for Java here

    This example using aspectwerkz is very similar to your case, is basically adding post and pre method handlers around a service execution.

    I’m not really familiar with AOP in PHP but there are some projects that you can use like this one.

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

Sidebar

Related Questions

I know there is a function somewhere that will accept a client rect and
I know there have been a few threads on this before, but I have
I know that for safety reasons that this is not easy to achieve, however
I have a WCF application that is using NetTcpBinding . I want to invoke
I know there is a registry key indicating the install directory, but I don't
I know there are a lot of positive things mod-rewrite accomplishes. But are there
I know there are quite a few line count tools around. Is there something
I know there is a way to add a IE control, how do you
I know there's some JAVA_OPTS to set to remotely debug a Java program. What
I know there is a Jackpot API http://jackpot.netbeans.org/docs/org-netbeans-modules-jackpot/overview-summary.html for programmatic access the the rules

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.