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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:38:33+00:00 2026-05-21T20:38:33+00:00

To make my question more concrete, let me pose it as a problem: situation

  • 0

To make my question more concrete, let me pose it as a problem:

situation description:

We have 3 abstract concepts:

Boss:  which has a number of employees
Worker:  that can execute some types of tasks
Task:  contains the semantics needed for a worker to execute it

In the implementation/subtypes we have a number of different types of workers and different types of tasks.
A specific type of worker can execute certain types of tasks (subset of all types)

problem to solve

Now the boss has a task of known type he wishes to see executed, he does not know the types of workers he has (only abstract type/interface).
What kind of interface(s) could the worker implement/what could the boss do to find out?

ways to solve it that I can think of

I found this two ways, but there probably are other&better ways:

1) we make an class for every task type implementing the empty task interface
give the worker an execute(task) function:
in the implementation of execute(task) try to typecheck/cast task to all tasktypes that type of worker can perform. If none of the typechecks pass, we throw a taskNotSupportedException.
the boss can now give tasks to workers until no exception is thrown.

2) we now do not have task classes but
define an capability interface for every task type with the function dotaskType(taskinfo)
a worker implementation can now implement capability interfaces dependant of what its capabilities are.
the boss now can check until a worker with the proper capability is found (typechecking)
and then give him the task knowing he can execute it.

I did not test 2 and I do not have that much experience in java but this should be possible (or something very similar).

I also prefer 2 over 1, because 1 seems improper (cascade of casts) and interfaces are a natural way to define what an instance of a class can do, also with interfaces you could group capabilities/create hierarchies. (also in my current implementation (1) the Task interface is empty, so tasks do not have much in common and info is passed through the constructor (which would be parameters of functions in method 2) and retrieved by gets.

I was wondering in what other way you would/could implement (adjusting 1 or 2?) this or which of the two you prefer and why.
(efficiency is not important, modulation/abstraction/maintainability is!)

  • 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-21T20:38:34+00:00Added an answer on May 21, 2026 at 8:38 pm

    Don’t use exceptions for this. Exceptions should be used for exceptional situations, and not being able to perform some task seems to be normal.

    I would add a method

    boolean isAbleToExecute(Task task)
    

    in the Worker class, and have the boss iterate through his workers and find a worker able to execute the task before assigning it.

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

Sidebar

Related Questions

Edit: Just wanted to make the question I have more clear. I pretty much
I have simplified my design to make this question more clear. (Design of models
** This question has been edited to make it simpler and more focused **
Let me know if I have to make this more concise, if you don't
I asked a somewhat related question but I want it to make it more
My question may not make sense but I have valid reason. We use .net
I have some question: How to make a role based web application? Such as
I have a (potentially dumb) question about the C++ STL. When I make a
This is a more concrete question that is connected with my previous one. I
Similar question to, Does it make sense to have multiple tomcat instances on the

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.