Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Multiple SingleCores instead of MultiCore  (Read 7279 times)
greenhorn
Newbie
*
Posts: 1


View Profile Email
« on: April 15, 2009, 06:44:14 »

Hi,

Imagine an pure AS3 (not Flex!) application like this:

- A main-application, which provides several UI-Elements, forms, menus etc.
AND
- a game-application which can be started from our main-app.

- We have no flex-modules, just 2 different MVC-Trees to seperate Game-code from MainApp-code.

Both apps have a MVC-like structure. So we decided to use the PMVC-Multicore-Version.

Some questions popped up:
- is it valid to interact from one core to the other like this??:
  (e.g.: GameCore wants to inform MainCore):
    -> ApplicationFacade.getInstance("main").sendNotification(SURPRISE);

AND

- maybe this is a stupid question, but:

Why can't we just setup 2 SingleCore-Facades instead of the multicore approach? Thus they are different singletons there should be no interference? Would that work? What's the advantage of multicore?

Please enlighten me!  :o

« Last Edit: April 15, 2009, 06:48:05 by greenhorn » Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #1 on: April 15, 2009, 09:54:47 »

You can't have 2 instances of the same class be singletons when they both are running under the same Virtual Machine. That is why multi-core exists. To communicate between cores have a look at either the PIpes Utility or Fabrication (which uses Pipes). Or you could use Interfaces. Either way you can't have two single-core PMVC apps running under the same Virtual Machine.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: April 15, 2009, 03:16:17 »

Don't retrieve the other core's facade and manipulate it. This defeats the entire purpose of modularizing your app.

Although you may control the entire codebase, from a best practices perspective, always imagine that the other core was written by someone else, and therefore you don't know the internals of it, and specifically you don't know the notification mappings that have been set up inside the other core. This is just standard OOP encapsulation/data hiding.

For this reason you have two options for communicating between cores: interfaces and pipes.

With Interfaces, two communicating cores implement one or more known interfaces, have uni- or bi-directional references to each other and invoke interface methods on each other.

With Pipes, you use the MultiCore Pipes utility to connect the cores, and send IPipeMessages to each other via the pipelines. The Message class from the utility can be used out-of-box, or subclassed to give specific properties.

Examine the Flex Modularity and PipeWorks demos respectively to see these two approaches in action. Sure, they're Flex, but the concept is exactly the same. There is no difference in the PureMVC part, only the way your view hierarchy is built.

-=Cliff>
Logged
Pages: [1]
Print