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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:11:27+00:00 2026-06-04T21:11:27+00:00

In my current project, I am trying to make a uniform interfaces of all

  • 0

In my current project, I am trying to make a uniform interfaces of all sensor driver.

For instance, Temperature sensor has a temperature sensor driver to get data from
it.

Now, my problem is each sensor response with its own data Object. I have written following example of Temperature Sensor. How can I make sensor driver interface uniform, so programmer should only know SensorResonse (not TempSensorResponse).

public class TempSensor implements Sensor {


    /**
     * Returns a SensorInfo object that describes this sensor.
     */
    @Override
    public TempSensorInfo getSensorInfo() {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * Asks the sensor for a (possibly old) datapoint. Synchronous: returns
     * immediately, even if that means returning an old value.
     */
    @Override
    public TempResponse getData() {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * Asks the sensor for a new datapoint. Asynchronous.
     *
     * @param handler A Handler object to be executed when the sensor has a
     * new value. If this Sensor is event-based, this method starts listening
     * for data, and calls the handler whenever new events are detected.
     */
    @Override
    public void getData(SensorListener handler) {
        // TODO Auto-generated method stub

    }

}

/**
* A SensorResponse is the response that a sensor passes to its callee whenever
* it is asked for some data. It carries both the sensor data itself as it does
* some metadata about it, such as the SensorInfo of the sensor that produced
* this response.
*/

public class TempResponse extends SensorResponse {


    public TempResponse(TempSensorInfo sensorInfo, TempSensorData payload) {
        super(sensorInfo, payload);
        // TODO Auto-generated constructor stub
    }

}
  • 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-04T21:11:28+00:00Added an answer on June 4, 2026 at 9:11 pm

    Use generics:

    Make an interface/base classes.

    public interface ISensor 
        <I extends ISensor.SensorInfo, 
         R extends ISensor.SensorResponse, 
         L extends ISensor.SensorListener> 
    {
    
        /**
        * Returns a SensorInfo object that describes this sensor.
        */
        public I getSensorInfo();
    
        /**
        * Asks the sensor for a (possibly old) datapoint. Synchronous: returns
        * immediately, even if that means returning an old value.
        */
        public R getData();
    
        /**
        * Asks the sensor for a new datapoint. Asynchronous.
        * 
        * @param handler
        *            A Handler object to be executed when the sensor has a new
        *            value. If this Sensor is event-based, this method starts
        *            listening for data, and calls the handler whenever new events
        *            are detected.
        */
        public void getData(L handler);
    
        public static class SensorInfo { }
        public static class SensorResponse { }
        public static class SensorListener { }
    }
    

    Make your sensors implement/extend the interface/classes:

    public class TemperatorSensor 
        implements ISensor 
            <TemperatorSensor.TemperatorInfo, 
             TemperatorSensor.TemperatorResponse, 
             TemperatorSensor.TemperatorListener> 
    {
    
        @Override
        public TemperatorInfo getSensorInfo() {
            // TODO Auto-generated method stub
            return null;
        }
    
        @Override
        public TemperatorResponse getData() {
            // TODO Auto-generated method stub
            return null;
        }
    
        @Override
        public void getData(TemperatorListener handler) {
            // TODO Auto-generated method stub
        }
    
        public static final class TemperatorInfo extends ISensor.SensorInfo { }
        public static final class TemperatorResponse extends ISensor.SensorResponse { }
        public static final class TemperatorListener extends ISensor.SensorListener { }
    }
    

    Without using Generics:

    Base interface/classes

    public interface ISensor {
    
        /**
         * Returns a SensorInfo object that describes this sensor.
         */
        public ISensor.SensorInfo getSensorInfo();
    
        /**
         * Asks the sensor for a (possibly old) datapoint. Synchronous: returns
         * immediately, even if that means returning an old value.
         */
        public ISensor.SensorResponse getData();
    
        /**
         * Asks the sensor for a new datapoint. Asynchronous.
         * 
         * @param handler
         *            A Handler object to be executed when the sensor has a new
         *            value. If this Sensor is event-based, this method starts
         *            listening for data, and calls the handler whenever new events
         *            are detected.
         */
        public void getData(ISensor.SensorListener handler);
    
        public static class SensorInfo { }
        public static class SensorResponse { }
        public static class SensorListener { }
    }
    

    Extended interface/classes

    public class TemperatorSensor implements ISensor {
    
        @Override
        public SensorInfo getSensorInfo() {
            // TODO Auto-generated method stub
            return new TemperatorInfo();
        }
    
        @Override
        public SensorResponse getData() {
            // TODO Auto-generated method stub
            return new TemperatorResponse();
        }
    
        @Override
        public void getData(SensorListener handler) {
            if (handler instanceof TemperatorListener) {
                // TODO Auto-generated method stub
            }
        }
    
        public static final class TemperatorInfo extends ISensor.SensorInfo { }
        public static final class TemperatorResponse extends ISensor.SensorResponse { }
        public static final class TemperatorListener extends ISensor.SensorListener { }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my current OpenGL project I am trying to make the links of a
What I'm trying to do is, to get local clone of dropbox project, make
I am trying to make the jump from data-centric design and development into DDD
I'm trying to make Core Data objects inherit from my own custom class rather
I'm a .NET Developer trying my hand at Java. My current project has a
I'm trying to convert a current Django project in development to use zc.buildout So
this is for a small project of mine, I'm trying to set the current
Our current project has ran into a circular dependency issue. Our business logic assembly
for my current project i need to consume messages from many destinations (from hundreds
In my current project, I want to convert List<String> to RegionLabel Object. For instance,

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.