Skip to content

Doubt about Sensor implementation using Inner Classes #121

Closed

Description

@jabrena

It is necessary to check the UML design for the inner class approach used with Sensors in LeJOS.

Current UML design is here:
https://raw.githubusercontent.com/ev3dev-lang-java/ev3dev-lang-java/next-release/docs/uml/graph.png

@Asw1n Why sensors use Inner classes?

Activity

  1. self-assigned this
    on Apr 3, 2016
  2. added this to the milestone on Apr 3, 2016
  3. changed the title [-]Refactor Sensor Innerclasses[/-] [+]Doubt about Sensor implementation using Inner Classes[/+] on Apr 3, 2016
  4. Asw1n commented on Apr 4, 2016

    @Asw1n

    Let me start with some real world observations. A sensor is a piece of hardware that measures an aspect or some aspects of the world. The more complex sensors can measure different aspects. The IR sample for example can measure both distance and angle. Sometimes a sensor can measure different aspects at the same time, sometimes it needs to be configured to measure one aspect out of several possibilities.

    In leJOS we say that to measure a specific aspect the sensor must be in the right mode for this. To measure reflected light a light sensor must be in RedMode. To measure ambient light it must be in AmbiantMode.

    There are basicly two ways to implement the idea of a mode. One is to have a sensor class that can be configured for each mode. The sensor class would then need a method like setMode. There are drawbacks to this approach. The biggest one is that you can never be sure that a sensor is in the right mode, some other thread might have changed it.
    Another approach is to have a different class for each mode that a sensor supports. This is the solution leJOS adapted. The RedMode class always measures reflected light, the ambientMode class always measures ambient light. This solution does not have the drawback of the previous solution. One can even have the two classes active at the same time. There are drawback though. Both classes use the same piece of hardware, so they probably share a lot of functionality. Also, users think in terms of sensors, not in terms of modes. To overcome this drawback leJOS bundles the mode classes belonging to one sensor in a sensor class. This class provides the ability to really talk to the sensor and configure it for each mode. It also provide the mode classes to the user by means of the getMode methods. As the mode classes are tightly linked to the sensor class and share the resources provided by the sensor class it is logical design decision to implement them as inner classes.

    As to the question that started the question about inner classes. I do not think there is a need for an EV3DEV alternative for mode classes. They do not need an ev3dev implementation as it is the sensor class that actually talks to the sensor, not the mode class.

    Aswin

  5. modified the milestones: , , v0.5.0, v0.4.0 on Jan 2, 2017
  6. modified the milestones: v0.6.0, v0.5.0 on Feb 20, 2017
  7. modified the milestones: v1.0.0, v0.6.0 on Mar 25, 2017
  8. modified the milestones: v1.0.0, v0.8.0 on Jan 10, 2018
  9. modified the milestones: v0.8.0, v1.0.0 on Mar 13, 2018
  10. modified the milestones: v1.0.0, v0.9.0 on Apr 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions