My friend is a stupid moron and cannot program

Started by
7 comments, last by tok_junior 18 years, 3 months ago
Okay, this time it's a question from my friend (my friend not being a metaphor for me). Though obviously, the fact that I'm asking for him means that I don't know the answer either... Anyways, the question is... in a fairly large system, with multiple large components, how exactly do the components go about talking to one another, and calling each other's methods? Does each one get passed a reference to every other component when it is instantiated? Does each one pass the message to the class that created everything, and communicate through that? Do you just go ahead and make them all singletons (my favourite method :))? Or do you have to implement some cunning and hardcore message passing scheme? What's the general way all of this stuff is done? Bear in mind this is all in the context of Java GUIs when replying :) Thanks muchly for your help, people.
Advertisement
Well what they COULD do is that with the instancing they register themself, with a 'superclass' which globally known and handles every message they all send to eachother.

What you often see in User Interface, that they usually have a parent/child relationship (often defined when the class/object/component instanced). which also allowes them to synchronise.

I'm not familiar with the exact inner workings of COM (Component Object Model), but the interfaces that are all derived from the 'IUnknown' interface and all have there on GUID (Globally Unique ID) that is registered in the register of the OS. Somehow they can commune with eachother in some special way.

Hope this gives you more attachment point to look into.

Regards,

Xeile
I think you (or your friend) would do well to read this:

COM and DCOM in Microsoft Windows CE 3.0
Quote:Anyways, the question is... in a fairly large system, with multiple large components, how exactly do the components go about talking to one another, and calling each other's methods? Does each one get passed a reference to every other component when it is instantiated?

Sort-of. Interfaces are established that determine what other components a componet will communicate with. The host application is responsible for instantiatng a component and wiring it up with other components.

Have a look at this this explanation of the IoC design pattern.
Free Mac Mini (I know, I'm a tool)
In large systems, the programmers need to define some sort of interface specifications to define how these components should communicate together. Large systems tend to be built by more than one programmer, so the development goes separately. Without interface specifications, there could be mismatching between the components, for example, component A needs a reference to and access to some functions in component B but component B is not built for it and when these two components are put together, the system crashes. You want to avoid this.

In case of COM/DCOM, for example, a function Release() is necessary to destruct objects, and that is part of the interface specifications. But it really is up to you.
I don't know a whole lot about java, or programming in general, ut since it's Object oriented, my first instinct would be to swap addresses, but make sure that you have everything properly encapsulated. of course, all of your methods described work, including the cunning and hardcore message passing system, which is just silly, considering the simpler methods available.

Go with whatever you are most comfortable with, unless your looking for a challenge.
It's different depending on the context.
In the case of a GUI-system I'd keep a masterclass that all controls were children of. The masterclass (a dialog window for example) would then be able to query the direct children for data. If data is needed for subchildren it should still pass through the hierarchy, up through the direct children.
Child controls should never be able to communicate directly, and since the master object is in control they never have to. The programmer knows what data is needed, and can implement the needed algorithms in the master object.
Hmm, so I guess it is as I thought, there isn't really much of a standard way of doing this... Thanks for your thoughts though. I think he's going to go for a message handling class to forward on calls to functions in other classes and such like, this seems like the most elegant method presented.
Yes, an event-based system is indeed one way to go, when coupled with a "bulletin board". Ie, you store the messages in a queue that all the controlls can access, and then they can just react to the ones concerning them.
Which is exactly the way Windows works.

This topic is closed to new replies.

Advertisement