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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:00:39+00:00 2026-06-10T05:00:39+00:00

I have two coupled classes DhcpServer and SessionManager . I got the following requirements

  • 0

I have two coupled classes DhcpServer and SessionManager. I got the following requirements in my specs that led to that coupling:

  • DhcpServer must not issue an IP address lease if SessionManager forbids that (e.g. an error occurred while creating a session)
  • SessionManager must start a session upon creation of a new lease by DhcpServer and destroy a session as soon as that lease expires or gets released explicitly by a client
  • On the other hand DhcpServer must destroy the lease if SessionManager stopped a corresponding session (e.g. by sysadmin’s request)

At first it was tempting to put all the code into a single class. But the responsibilities were distinct, so I split them into two and created two interfaces:

class ISessionObserver(object):
    def onSessionStart(**kwargs): pass
    def onSessionStop(**kwargs): pass

class IDhcpObserver(object):
    def onBeforeLeaseCreate(**kwargs):
        """
        return False to cancel lease creation
        """
        pass
    def onLeaseCreate(**kwargs): pass
    def onLeaseDestroy(**kwargs): pass

Then I implemented IDhcpObserver in SessionManager and ISessionObserver in DhcpServer. And that led to coupling. Even though the classes do not depend on each other directly they do depend on the interfaces declared in each other’s packages.

Later I want to add another protocol for session initiation leaving SessionManager‘s logic intact. I don’t want it to implement IAnotherProtocolObserver as well.

Also DHCP server as such has nothing to do with my notion of session. And since there’s no DHCP protocol implementation for Twisted (which I’m using) I wanted to release it as a separate project that has no dependencies neither on SessionManager nor on its package.

How can I satisfy my spec requirements while keeping the code pieces loosely coupled?

  • 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-10T05:00:41+00:00Added an answer on June 10, 2026 at 5:00 am

    A good way to decouple classes is to use events.

    So what you need to do is to “fire” events when something happens. Example: Send an event “session created” when the SessionManager could create a session. Make the DhcpServer listen for that event and prepare a lease when it receives it.

    Now all you need is a third class which creates the other two and configures the event listeners.

    The beauty of this solution that it keeps everything simple. When you write unit tests, you will always only need one of the classes because all you need is to check whether the correct event has been fired.

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

Sidebar

Related Questions

I have two classes that I use to access two different tables in my
I have two classes that can act as a delegate of a third class,
I have two classes that communicate with each other (processes in each class depend
I have two classes (this is C#) that are very similar except they each
I have two different classes that have the same class as a private field.
I have two classes (MVC view model) which inherits from one abstract base class.
I have a couple classes that have nearly identical code. Only a string or
I have a question re object-oriented design - I have two classes, a Map
I'm developing a library in which I have two groups of classes: A) a
OK, I've tried but I just don't get it. I have two classes logger

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.