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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:55:11+00:00 2026-06-09T03:55:11+00:00

Assume: A simple modular java library has only two module: package com.mycorp.lib.logger; public class

  • 0

Assume:
A simple modular java library has only two module:

package com.mycorp.lib.logger;
public class LogcatLogger implements Logger {

    @Override
    public void out(LogcatLogger.LogMessage message){
        Log.i("TAG", message.status);
    }

    ...
}

package com.mycorp.lib.webservice;
public class JsonWebservice implements Webservice {

    @Override
    public void onErrorFound(String status) {
        LogcatLogger.LogMessage message = new LogcatLogger.LogMessage();
        message.status = status;
        LogcatLogger.out(message);
    }

    ...
}

Question:
How to make com.mycorp.lib.webservice and com.mycorp.lib.logger independent like this? ( client application can invoke methods too )
Target Design

Notes:
I try Command Pattern before:
Result: api has many methods and many command class must create

Update1:
Added LogMessage as nested static class of LogcatLogger for more challenging situation

Update2:
Target Design image added.

Any help appreciated.

  • 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-09T03:55:12+00:00Added an answer on June 9, 2026 at 3:55 am

    Use the Strategy Pattern. Basically, make LogcatLogger implement a custom interface, and reference that interface in the service.

    package com.mycorp.lib.invoker;
    public interface Logger {
        void out(Loggable message);
    }
    
    package com.mycorp.lib.invoker;
    public interface Loggable {
        void setStatus(String status);
        String getStatus();
    }
    
    package com.mycorp.lib.invoker;
    public class LoggableFactory {
        public static Loggable createDatabaseLogMessage() { return new DatabaseLogMessage(); }
        public static Loggable createWebserviceLogMessage() { return new WebserviceLogMessage(); }
    }
    
    package com.mycorp.lib.logger;
    public class WebserviceLogMessage implements Logger {
    
        @Override public void out(Loggable message){
            Log.i("TAG", message.getStatus());
        }
    
        ...
    }
    
    package com.mycorp.lib.logger;
    public class DatabaseLogMessage implements Logger {
        @Override public void out(Loggable message) {
            Log.i("JDBC",message.getStatus());
            otherFancyStuff(); // whatever ? :)
        }
    }
    
    package com.mycorp.lib.webservice;
    public class JsonWebservice implements Webservice {
        Logger out;
    
        JsonWebservice(Logger out) { this.out = out; }
    
        @Override
        public void onErrorFound(String status) {
            Loggable message = LoggableFactory.createWebserviceLogMessage();
            message.setStatus(status);
            out.out(message);
        }
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume a simple application, which has at the top the following navigation (pseudo
Assume we have a simple @Configuration : @Configuration public class FooBarConfiguration { @Bean public
Assume you have the following simple objects: class Order { public Customer[] Customers {
Assume I have this simple core with generics as genertest.vhd : -------------------------------------------------------------------------- library IEEE;
Assume I have a webpage where people submit java source code (a simple class).
Here is a simple example: Assume I have a customer table that has a
Assume a simple JPA entity class like this: @Entity(name=TASK) public class Task implements Serializable
Lets assume a simple Spring MVC Controller that receives the ID of a domain
Let's assume we have a simple internet socket, and it's going to send 10
This should be a really, really simple one, I would assume. I'm throwing together

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.