Dynamic Objects
OverviewObjectiveLearn how to create dynamic objects that you can addmethods and variables too on the fly.Requirements Un...
Follow Along With A Code          Example1. Download a copy of the example code at  www.prodigyview.com/source.2. Install ...
The ObjectIn ProdigyView, PVObject and PVStaticObject are verypowerful classes. Have the design patterns to improve devel...
Create Our Class We can start learning about how to use an object by creating an empty class. Yes, just merely define a cl...
Anonymous           functions/closuresNext step is to create our anonymous functions . Thesefunctions are eventually going...
Adding the MethodsWe have a class with no methods and we have twoanonymous functions. Ok we are ready to go. Becauseour cl...
Calling the Methods  Ok so we’ve added the methods to our object that was  once empty. Now we can call those methods by us...
PVCollectionIf you remember PVCollection, we could add informationand retrieve information from it at any time.Every class...
Adding Variables   When we created our class, it was empty with no   variables. Let’s change that by adding some variables...
Get the variablesLike the methods, we can now get the variables that wereassigned to our once empty object. Also we can it...
PVObjectsPretty cool? Well this is only the tip of the ice berg.With a clear understanding of adding methods andvariables ...
Challenge!To better understand the concepts covered, complete theoptional challenge below.1. Start out with an empty class...
The Not So Obvious1. Adding a variable to an object can also be accomplish   by using the method addToCollection. But the ...
Review To create dynamic objects, make sure the class  extends PVObject or PVStaticObject Closures/anonymous functions c...
API ReferenceFor a better understanding of the Collections and theIterator, check out the api at the two links below.PVSta...
Upcoming SlideShare
Loading in …5
×

Creating Dynamic Objects PHP

2,527 views

Published on

Learn how to create dynamic objects that you can add methods and variables too on the fly

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,527
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Creating Dynamic Objects PHP

  1. 1. Dynamic Objects
  2. 2. OverviewObjectiveLearn how to create dynamic objects that you can addmethods and variables too on the fly.Requirements Understanding of PVCollections Understanding of Closures/Anonymous FunctionsEstimated Time10 minutes www.prodigyview.com
  3. 3. Follow Along With A Code Example1. Download a copy of the example code at www.prodigyview.com/source.2. Install the system in an environment you feel comfortable testing in.3. Proceed to examples/design/Objects.php
  4. 4. The ObjectIn ProdigyView, PVObject and PVStaticObject are verypowerful classes. Have the design patterns to improve development Enable Object Oriented Programming Enable Aspect Oriented Programming Easily mutable codeBefore we get into the higher level constructs, lets startwith understanding PVObjects and PVStaticObjects.
  5. 5. Create Our Class We can start learning about how to use an object by creating an empty class. Yes, just merely define a class with nothing in it.Extend PVObject or PVStaticObject Take notice it’s empty, no methods or variables
  6. 6. Anonymous functions/closuresNext step is to create our anonymous functions . Thesefunctions are eventually going to become the class’smethods.
  7. 7. Adding the MethodsWe have a class with no methods and we have twoanonymous functions. Ok we are ready to go. Becauseour class extends PVObject, we have access to a methodcalled addMethod(). This method will allow us to add ouranonymous functions as methods that become part of theclass. Add our anonymous functionSet the name of the method
  8. 8. Calling the Methods Ok so we’ve added the methods to our object that was once empty. Now we can call those methods by using the -> operator and the name we assigned the method.Name of the methodRemember, the anonymous function $write_email accepted two parameters.
  9. 9. PVCollectionIf you remember PVCollection, we could add informationand retrieve information from it at any time.Every class that extends PVObject and PVStaticObjecthas a PVCollection built in. This makes it possible to adddata to an object and also iterate through the objectsdata.Let’s take a look on the next slide.
  10. 10. Adding Variables When we created our class, it was empty with no variables. Let’s change that by adding some variables. The method addToCollectionWithName is a method inherited from PVObject and will allow us to add variables to the objects collection that can be retrieved later. Or you can explicitly add a variable by assigning it using the ‘->’ operator.Name of the variable Value associated with the name Name of the variable Value associated with the variable
  11. 11. Get the variablesLike the methods, we can now get the variables that wereassigned to our once empty object. Also we can iteratethrough the variables that were added.Get the variables by calling the name assigned to them
  12. 12. PVObjectsPretty cool? Well this is only the tip of the ice berg.With a clear understanding of adding methods andvariables to an object, we have the ability to create verydynamic objects.Once combined with design patterns, you will able toleverage aspect oriented programming and othercapabilities that will make building an applicationincredibly easy and robust.
  13. 13. Challenge!To better understand the concepts covered, complete theoptional challenge below.1. Start out with an empty class.2. Add a variable to the class3. Add a function to this call that will retrieve the variable and pass it to another function that alters the result.4. Then pass the altered result back to where the function was originally called.
  14. 14. The Not So Obvious1. Adding a variable to an object can also be accomplish by using the method addToCollection. But the variable will not be assigned a key for accessing it later. The variable can retrieved when using the getIterator() method.2. All objects have a PVCollection. All variables are assigned and pulled from this collection behind the scenes.
  15. 15. Review To create dynamic objects, make sure the class extends PVObject or PVStaticObject Closures/anonymous functions can be added to using the addMethod function Variables can be added using the addCollectionWithName() method or explicitly applying the variable with ‘->’ operator.
  16. 16. API ReferenceFor a better understanding of the Collections and theIterator, check out the api at the two links below.PVStaticObjectPVObject More TutorialsFor more tutorials, please visit:http://www.prodigyview.com/tutorials www.prodigyview.com

×