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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:56:01+00:00 2026-05-18T08:56:01+00:00

intro code: public interface Course { /** * returns the number of units (hours)

  • 0

intro code:

public interface Course {

    /**
     * returns the number of units (hours) a specific course is
     */
    public int units();

    /**
     * returns the number of students signed up for the course
     */
    public int numOfStudents();

    /**
     * returns the maximum number of students the course can have signed up to it
     */
    public int maxNumStudents();

    /**
     * returns whether or not the student is enrolled in the course
     */
    public boolean registered(Student s);

    /**
     * enrolls s in the course
     * 
     * @pre     this.registered(s) == false
     * @pre     this.numOfStudents() < this.maxNumStudents()
     * 
     * @post    this.registered(s) == true
     * @post    this.numOfStudents() == $prev(this.numOfStudents()) + 1
     */
    public void register(Student s);

}


public interface Student {

    /**
     * enrolls the student in course c
     * 
     * @pre     c.registered(this) == false
     * @pre     c.numOfStudents() < c.maxNumStudents()
     * @pre     this.totalUnits() + c.units() <= 10
     * 
     * @post    c.registered(s) == true
     * @post    this.totalUnits() == $prev(this.totalUnits()) + c.units()
     */
    public void register(Course c);

    /**
     * return the total number of units this student currently is enrolled in
     * 
     * @pre     true
     * @post    0 <= $ret <= 10
     */
    public int totalUnits();

}

in the example code im trying to describe two separate entities (interfaces/classes/whatever) which on the one hand should be (i would like, at least) loosely coupled but on the other hand do depend on each other and require a certain knowledge of each other.

in the above scenario i would need a third class that actually unites them into a working system. its ugly because as of now, the above definition is as loosely coupled as can be – student.register(c) only changes the student object, and course.register(s) only changes the course object. so a unifying class would have to run both s.register(c) and c.register(s).

although if i relogate all the register() logic to one class then i tightly couple them.

is there a cleaner way of designing this?

  • 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-18T08:56:02+00:00Added an answer on May 18, 2026 at 8:56 am

    By using interfaces you are already reducing the level of dependency between concrete objects and that is a good thing. Some dependency is necessary for your system to work so you have to decide how much you want to tolerate.

    Consider that a Student in your system can register for a course. Since Course is an interface it may be possible to implement a number of different types of Courses and the student will then be able to register for any of them. As long as the student only knows the Course interface that should be fine. And the same thing for the Course, it only knows the Student interface not the concrete Students.

    Just one thing. In a situation where you have a bi-directional association as you describe I like to make one side the owner of the relationship. That is, I can decide that Student owns the relationship and as such, a Student may register for the Course but the Course does not Register the Student.

    Then all client code will make a single call s.register(c). The register in Student will then take care of the inverse side of the relationship. This reduces the need of client code to know both sides of the relationship.

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

Sidebar

Related Questions

I was trying to code along with the PDC2008 Intro to F# video .
First a little intro: Last year i wrote this http://dragan.yourtree.org/code/canvas-3d-graph/ Now, i want to
I'm look for good alternatives to invoking a specific interface from a generic framework.
I often run into code that has to perform lots of checks and ends
Could someone help me translate the following pseudo-code into code understood by Helicon Tech's
Some years ago I was told about a study into code reuse. Apparently it
Suppose I am entering validation code into my model of multi-language publication database. The
how do I translate this code into jython? ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file
I'm trying to abstract out all database code into a separate library and then
Is there a general procedure for programming extensibility capability into your code? I am

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.