D
D
DarthRamone2011-10-21 15:19:32
OOP
DarthRamone, 2011-10-21 15:19:32

OOP gurus, help me decide

There are two objects of two different classes that must work with the network. I am writing in the most detached way, do not blame me. So. There is an object of the current Internet session, with which, in theory, these two objects should work in turn, for example:

http = new httpSession();

object1 = new Class1();
object2 = new class2();

object1.work(http);
object2.work(http);

How would it be more correct to directly pass one session sequentially to these objects, as shown in the example above, or create its own session inside each object and work with it?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vumik, 2011-10-21
@Vumik

Singleton pattern
1 session object, the ability to access it from almost anywhere in the code

X
xappymah, 2011-10-21
@xappymah

Sessions in any case need to be created outside and passed to objects so as not to overload objects with the functionality (creating Internet sessions) for which they are not intended.
Further, in this particular abstract case, it is more logical to use one session. At least I see no reason to create a second one.

F
f3ath, 2011-10-21
@f3ath

It is more correct to pass the session object, and not create it inside consumer objects. Google for "dependency inversion".

L
linqu, 2011-10-21
@linqu

I think it's a matter of object interaction. Logically, one connection equals one session. But there may be nuances. For example, two threads: control and data. Installed at the same time, work in parallel. Then there must be one shared session object for both connections (the flow of control may change the session, and the data flow may depend on new data). Overall result: I think it all depends on the actual application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question