How can I use IObservable / IObserver to get rid of my "god object"?

In the system I'm currently working on, I have many components that are defined as interfaces and base classes. Each part of the system has certain points where they interact with other parts of the system.

For example, a data preparation component prepares some data, which ultimately must go into the data processing part, a communication component needs to request different components for their status for relaying to an external one, etc.

I am currently gluing these parts of the system using an “object-god,” or an object with deep knowledge of the various parts of the system. It registers with events here and transfers the results to methods there, creates a callback method here and returns the result of this method there and passes many requests through a multi-threaded queue for processing, because it “knows” certain actions to run on STA streams, etc.

While this is convenient, it concerns me that this type knows so much about how everyone else in the system is designed. I would prefer a more general hub that can be provided with instances that can expose events or methods or callbacks or that can use them.

I saw more about the IObservable / IObserver features in a reactive environment and which are currently loading in .NET 4.0 (I suppose).

Can I use this template to replace my “god object”? How can I do it? Are there any resources to use this template for this particular purpose?

+4
source share
1 answer

It would seem that you can replace your god object with what MSDN describes:

To create sophisticated event processing (CEP) using Microsoft StreamInsight, you create structures that define events, objects that produce and consume events, and query templates that contain the business logic needed to process events.

Our team will not switch to .Net 4.0 in the near future (unfortunately). Thus, we walked around the object-object with the divine object, creating a user structure similar to that provided by MAF / MEF. This created a distributed knowledge base using what Microsoft calls an adapter. Each adapter is responsible only for its own module, transfers data, events, etc. There is a general operator that receives data and events, processes and passes back to the appropriate adapter.

My understanding of IObservable and IObserver allows me to believe that a god object is not needed - it actually creates a distributed knowledge base about what happens in different parts. An obvious advantage of these interfaces is that an intermediate communicator (i.e., adapter) is no longer required. Thus, the distribution of knowledge is indeed in the derived class IObservable. This model inherently draws a connection with the speaker / defendant - there is no mediation / arbitration class.

+1
source

Source: https://habr.com/ru/post/1301466/


All Articles