-2

My scenario involves the following classes:

enter image description here

I have three types of Peer that creates a RegistryType instance because its methods are needed. Same for Identity class. Each PeerType need 0 or all the RegistryType methods in order to accomplish their work. Every Peer is then run by creating a Server instance that makes use of one of the methods defined by the Peer by passing a callback.

What I'm trying to achieve is to solve the tight coupling between the PeerType classes and the RegistryType class. My idea is to define a general Peer class from which every type inherits and define the dependency with the RegistryType there.

The target language is Python so either constructing the Peers with a RegistryType or a Registry is ok.

Even after defining a new Peer class to encapsulate the RegistryType I reckon the two classes are still tight coupled so (maybe) a solution would be to pass a RegistryType instance to the Peer class instead of constructing it inside its constructor.

I hope to receive some great suggestions. Thanks.

EDIT1: I'll try to be more specific.

enter image description here

Every PeerType implements some logic that is passed as argument to the run method of the Server. This method depends also on the OTT_RPC class because it needs the callback_ottrpc function to create the HandshakeServer and accomplish the handshake (start_handshake).

My first problem is that, each peer type is run by a class Server, but Holder offers two different services that should be passed to the run method in contrast Verifier offers only one, so I need to solve this inconsistency.

Second, the circular dependency between Server, HandshakeServer and OTT_RPC.

6
  • 1
    I find the question very abstract. For one all of your classes have very abstract names, and you didn't describe what the classes are doing, so that gives very little context. Secondly you state your want to solve tight coupling, but not how it affects you. Tight coupling isn't necessarily a bad thing, but it can get in the way of making changes later on. Without knowing what the kind of problems you are running into, it is hard to just solve 'tight coupling'.
    – Helena
    May 4, 2021 at 19:19
  • 1
    I edited my question. May 5, 2021 at 8:44
  • Tight/loose coupling does not mean what you think it means. Having three classes have a reference to a particular type is not an instance of tight coupling.
    – Flater
    May 5, 2021 at 8:59
  • "Tight coupling is when a group of classes are highly dependent on one another" May 5, 2021 at 9:04
  • I don’t understand the inconsistency. I don’t see any circular dependency. Why don’t you ask a new question? May 5, 2021 at 15:45

1 Answer 1

1

Well Helena is right, this is very abstract. But consider use of the Strategy Pattern.

enter image description here

Here Peer abstracts away knowledge of the different Peer types. So long as that is possible then the Strategy Pattern will achieve a coupling improvement because Peer hides PeerType details.

2
  • I edited my question May 5, 2021 at 8:45
  • 1
    I like your diagram style, what tool did you make it with?
    – Flater
    May 5, 2021 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.