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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:07:10+00:00 2026-05-13T14:07:10+00:00

I have a situation in Java where I have an external device that I

  • 0

I have a situation in Java where I have an external device that I want to communicate via serial I/O. I know how to do this, but I’m now in a refactoring mode to make sure I’ve got a maintainable software package, & was looking for advice on what to do / not to do at a high level (specific questions below)

Conceptually, let’s say I have a low-level DeviceIOChannel interface with several methods (getInputStream, getOutputStream, and some other ones for controlling connection / disconnection detection, etc.), implemented by one or more classes that handle the I/O for various data link types (RS232, TCPIP, etc). Some of my software, let’s call it a Device class, is devoted to managing the I/O (parsing the input, constructing output, managing low-level state machines), but without knowing the details of how DeviceIOChannel does its thing (so I can use it with RS232 or TCPIP without having to change the Device class). So I’ll probably pass in DeviceIOChannel as a parameter to Device‘s constructor. I also would like to expose some sort of data model to the outside world.

  1. Does my partitioning of DeviceIOChannel / Device sound right?
  2. Device needs to be doing some things actively on a worker thread. What’s the best way to set this up? Should I have it create and manage its own Thread or ScheduledExecutorService? Or should I pass in a ScheduledExecutorService as a construction parameter?
  3. any thoughts (links to good articles on the web would be ideal!) about how to whether or not the Device class should have a startup() method distinct from construction? (doing all the initialization in construction makes me nervous… seems like class instance construction should be quick, and then lengthy stuff should be reserved for an init or startup phase that comes later.)
  4. What about whether to have a Device class with a pair of shutdown / restart methods, vs. no shutdown + requiring a new Device instance to be created?
  5. I’m still new to MVC architecture: would it make sense to create a DeviceDataModel interface that Device implements, or should I have some separate class DeviceDataModel that somehow has two-way communication with the Device class?
  • 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-13T14:07:11+00:00Added an answer on May 13, 2026 at 2:07 pm

    To answer your question one point at a time.

    1. Yes, it does sound reasonable.
    2. Yes, passing an abstraction for your threading will definitely make the class much more testable. Two dependencies in a constructor doesn’t sound unreasonable.
    3. Having a startup method adds more overhead (on method calls you have to check if startup was called, you can’t assume it), however I agree that such network activity on a constructor always looks weird to me when I see it. I think it is really a matter of style, but one advantage of a separate method is that if you need to debug or log state before starting, your Device class can express its configuration as an instance, rather than making it impossible for something else to get a handle on the object.
    4. I think the answer to this question depends almost entirely on how you handle #3. An API with no surprises would not have a way to restart if it started in its constructor, and would have a way if it started via a method.
    5. Given the network IO nature of this class, a DeviceDataModel interface is going to make the rest of the code much more testable. However, it need not be implemented directly by the Device class, but rather returned from a method of the Device class as an inner class, so it could communicate with the device class easily, but still be something that can be mocked or stubbed during testing. At least, as long as serialization of the the DeviceDataModel isn’t a requirement.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 415k
  • Answers 415k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer (...) and only attaching to whatever list item has .active… May 15, 2026 at 8:54 am
  • Editorial Team
    Editorial Team added an answer you need to disable anonymous auth for your IIS site… May 15, 2026 at 8:54 am
  • Editorial Team
    Editorial Team added an answer Edited: (removed original version, as it was more crap than… May 15, 2026 at 8:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.