6 Replies Latest reply on May 19, 2010 8:41 AM by Miggl

    Extending VO

    Miggl Level 1

      I would like to create a model object by extending a value object, in order to add functionality to the model. (Is this the right approach - I don't think functionality should be conatined in the VO?)

       

      One of the functions I want to add is the ability to extract a populated VO based on the current model, i.e.:

       

      public class myModel extends myValueObject

      {

           public function getVO():myValueObject

           {

                //return VO with data specific to this instance of the model.

           }

      }

       

      What is the best way to achieve this? I am admittedly still strugling with how to properly structure my FLEX app, as well as best practices for interacting with databases.

        • 1. Re: Extending VO
          TeotiGraphix Level 3

          Hi,

           

          Why do you want to extend and return an instance of a VO?

           

          This is such a debated topic but you are mixing two patterns, the ValueObject and Proxy.

           

          Sounds like you really want to proxy access to your value object in which you shouldn't subclass the value object.

           

          You could return a reference to it (Proxy) or allow access to only certain properties of it.

           

          Mike

           

          PS There are application frameworks out there that help with this in Flex. Google "Flex application frameworks"

          1 person found this helpful
          • 2. Re: Extending VO
            Miggl Level 1

            Hi TeotiGraphics,

             

            Thanks for taking a look at my question. There are two things that led me in this direction:

             

            1. I am developing an app that is targeted for both AIR and FLEX, so I want to avoid as much refactoring / recoding as possible. (I say this, because FLEX coupled with ZendFramework only needs value objects, and AIR needs a bit more than that.)

            2. I need my models / value objects to have more functionality than just the data points. For one, I need to have models contained in other models, as well as functions that take care of saving, loading, etc.

             

            I haven't looked at frameworks like Cairngorm yet, but have tried my hand at FlexOrm (which may hold the answers I need, but without documentation is utmost confusing).

             

            I understand how ZendFramework functions, and think that way -- so developing with value objects has been a rough ride for me, since I'm not used to it.

            What framework (in your opinion) more closely resembles ZendFramework?

             

            Thanks again!

            ~Mike

            • 3. Re: Extending VO
              UbuntuPenguin Level 4

              I'm not really sure about the ZendFramework , thought that was more of a php thing. Anyway , I would keep the vo the way it is, and have other objects perform functions on the vos.  The saving and loading shouldn't be part of the vo , if I remember correctly , that responsibility should be somewhere else such as SaveManager , LoadManager.  If you have a class B subclassing class A ( class B extends A ) , you don't need to have this in class B:

               

              public function returnA():A

              {

              }

               

              But if you must , I would have class B contain an instance of class A as in the old adage  "Composition over inheritance".  By the way  , I would use Mate as a framework , Cairngorm and PureMVC are a little "heavy" when it comes to Flex development.

              1 person found this helpful
              • 4. Re: Extending VO
                TeotiGraphix Level 3

                Hi,

                 

                I agree. The Proxy pattern is what you are describing. The Proxy "uses" the vo's data and can have logic in it to act.

                 

                I would not subclass a vo and access the same type of vo through composition. That is giving that class hierarchy 2 responsibilities which leads to trouble.

                 

                Mike

                • 5. Re: Extending VO
                  Miggl Level 1

                  Hi UbuntuPengiun,

                   

                  Thanks for your answer and pointing me to a new framework (Mate). I dislike Cairngorm because it has subscribes to non-conventional patterns (some might call them anti-patterns) that quickly lead to a slippery slope in bad programming or application architecture. Mate looks interesting as it appears to be an event-centric framework, which is precisely what client apps work with.

                   

                  I mentioned ZendFrame work because it works with established patterns and OO methodologies. Yes, it is only for PHP, but I was thinking of a framework like that for FLEX or AIR.

                   

                  I have been reading up on various frameworks over the past few days, and haven't yet come to a conclusion. Perhaps I'll just forego a framework for now and only implement an ORM. I might structure all my classes, views, and controllers myself for the time being until I find something that really works. I haven't looked into PureMVC yet, but I will over the next few days.

                   

                  Thanks!

                  • 6. Re: Extending VO
                    Miggl Level 1

                    Yes, you're right. I actually found the implementation of the pattern for my classes. While I haven't got them working completely yet, I am getting closer.

                     

                    Thanks for the advice on the proxy pattern. I dug up my book on design patterns and will be studying it again this weekend. (It's been a year since I last opened it, and I've been away from programming for about 6 months, which doesn't help either.)

                     

                    Thanks!