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: Concept Question, proxy and vo for a chat  (Read 10978 times)
coulix
Full Member
***
Posts: 23


View Profile Email
« on: October 12, 2008, 03:20:39 »

Hi,

Firstly thank you for creating such a framework it forces good practices and unless you are a Pattern/OO wizard we need it !

I am new to AS3/Flex/pureMVC, in order to test my understanding of the framework i am trying to build yet an other chat with Flex/FMS and server side shared objects.

Please tell me if there is anything wrong in the following facts:
Simple case its a 1-1 chat.

- I dont need to store the messages received and typed in a messagesVO as an arrayCollection of String, i will just update the text widget of my Chat View Component by cummulating the chatmessage string attached to a notification sent by the proxy?

- I need a ChatProxy which will be an async remote proxy interfacing the remote shared object ?

- In a pureMVC jabber Chat demo around the author uses a custom chatEvent holding an id and a string, is there a need for custom events when we can pass Array as notification body. I guess there is an obvious use for it, but an example may be welcome.

PS:
If somehow i manage to build this small app after review i will add it to the contributions.

Thanks,
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #1 on: October 12, 2008, 09:53:10 »

is there a need for custom events when we can pass Array as notification body.

I think you can almost ALWAYS toss around generic objects ( [], {}, etc ). It will probably save you a few minutes up front, but why not create the VOs and have type safe messages being tossed around that are clearly defined against a documented interface (yay code completion!)?

In my simple chat application I am using a database, so it is a little different, but I keep a ChatSessionVO and ChatMessageVO going so that I can have nice logs and offline messaging and whatnot.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
coulix
Full Member
***
Posts: 23


View Profile Email
« Reply #2 on: October 12, 2008, 10:16:32 »

Thanks for these clarifications, It must have been my Python heritage that fooled me: no Strong Typing no ide and Magic ponies.
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #3 on: October 13, 2008, 05:34:10 »

I use Komodo for Python, it provides a lot of nice code completion, but ya, contextually speaking it is a big jump from python to actionscript.

They play really well together though. I tried to get into Java for my service tier, but I am back to Python. It is such a pleasant language to use :>
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: October 13, 2008, 08:13:42 »

@coulix From a 'simple as possible but no simpler' standpoint I'm in agreement with you. But from a 'buiding maintainable software' standpoint I'm definitely in agreement with Joel.

For your simply stated requirements, you've got it covered. But almost never is a piece of software concieved, written and then frozen. That was the initial goal with PureMVC, but it didn't stay at 1.0 for long. Point is, when you go to add the next feature, or the one after that, future you will think of past you as his best compadre for making it easy to extend.

And this yaya from a guy who sling Perl in vi for years. I, too forked the sign of the evil eye to the magic ponies.

But when a job situation forced me into Java and Eclipse (kicking and screaming the whole time, mind you), I finally saw the light. Once I really got OOP and the power of strong typing combined with an IDE that knew everything there is to know about the language, my productivity shot through the roof and my code became more solid and understandable by orders of magnitude.
Come to the dark side. We have cookies :)
-=Cliff>
Logged
coulix
Full Member
***
Posts: 23


View Profile Email
« Reply #5 on: October 14, 2008, 02:09:19 »

Thanks for these tips, i am trying hard to find the way of good coding practices.

I got the Chat app working in a pureMVC way, but before i dare to show the code here i have few questions on the architecture.

The Chat uses a connection to a FMS server, since i may extend my app with video and so on, i should separate the connection Handling form the ChatProxy.

Is a FmsConnectionService is a good way to this ? So far i did it this way:
The service is a singleton since i need only one connection, and it can send Notifications too.
(is it still a service then or should it be a proxy) ?

:
ackage org.edorado.edoboard.model.service
{
import org.puremvc.as3.interfaces.INotifier;
import org.puremvc.as3.patterns.observer.Notifier;

import flash.net.NetConnection;
import flash.events.NetStatusEvent;

    import org.edorado.edoboard.ApplicationFacade;
   
/**
* FMS connection Singleton
*
*/

public class FMSConnectionService extends Notifier implements INotifier
{
private var nc:NetConnection;

private static var instance:FMSConnectionService;

public function FMSConnectionService() {
setupConnection();
}

        /**
         * Create the required connection object and do any configuration
         */
        private function setupConnection():void {
            //A NetConnection is the pipe between Flex/Air and Flash Media Server
            nc = new NetConnection();
            //The NetStatusEvent is a dispatched status event for
            //NetConnection, NetStream, or SharedObject.
            //We want to know if the NetConnection has properly connected
            nc.addEventListener( NetStatusEvent.NET_STATUS, handlerOnNetStatus );
        }
       
        // Singleton Service
        public static function getInstance() : FMSConnectionService {
            if ( instance == null ) instance = new FMSConnectionService( );
                return instance as FMSConnectionService;
        }
       
        /**
         * Connect to the given URL
         */
         public function connect(url:String):void {
            nc.connect(url);
         }
 
         /**
         * Disconnect  the net connection
         */
         public function close():void {
            nc.close();
         }
               
        public function getNetConnection():NetConnection {
            return nc;
        }
       
       
                 /**
         *  This is the handler function of the NetStatusEvent for the NetConnection. 
         *  Here is where we can find out the connection status and send notifications 
         *  based on each result.
         */
         private function handlerOnNetStatus( event:NetStatusEvent ):void {
            var info:Object = event.info;
            trace(info.code);
            //Checking the event.info.code for the current NetConnection status string
            switch(info.code)
            {
                //code == NetConnection.Connect.Success when Netconnection has successfully
                //connected
                case "NetConnection.Connect.Success":
                    sendNotification(ApplicationFacade.CONNECT_SUCCESS, info.code);
                    break;
               
                //code == NetConnection.Connect.Rejected when Netconnection did
                //not have permission to access the application.   
                case "NetConnection.Connect.Rejected":
                    sendNotification(ApplicationFacade.CONNECT_REJECTED, info.code);
                    break;
               
                //code == NetConnection.Connect.Failed when Netconnection has failed to connect
                //either because your network connection is down or the server address doesn't exist.   
                case "NetConnection.Connect.Failed":
                    sendNotification(ApplicationFacade.CONNECT_FAILED, info.code);
                    break;
               
                //code == NetConnection.Connect.Closed when Netconnection has been closed successfully.         
                case "NetConnection.Connect.Closed":
                    sendNotification(ApplicationFacade.CONNECT_CLOSED, info.code);
                    break;
            }
        }
       
       
}
}

My chatProxy has a public  fMSConnectionService  variable that i can use to get the netConnection object.

Now, if i want to check for the success of my connection before i register the ChatProxy and ChatMediator. I would need to access the Service and call connect() from my ApplicationMediator and that is BAD from what i read, service should only be used by proxies.

What would be a good solution then ?

Thanks for the enlightment.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: October 14, 2008, 06:25:12 »

I would make the FmsConnectionService a Proxy, register it and later, have the ChatProxy (and any other Proxy that ends up needing the connection) retrieve the ConnectionProxy  in onRegister and check if the connection is valid. If not they can thow error, or ask the ConnectionProxy to retry, or unRegister themselves, as needed.

This is a Proxy acting as a Delegate for services.

-=Cliff>
Logged
Pages: [1]
Print