The PEAK Developers' Center   Diff for "ComposingHierarchies" UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Ignore changes in the amount of whitespace

Differences between version dated 2003-10-29 12:15:32 and 2005-05-12 08:35:35 (spanning 6 versions)

Deletions are marked like this.
Additions are marked like this.

The purpose of this page is to give a quick overview of how to compose component hierarchies using the PEAK framework, using working code. I have inlined comments in the code example, so hopefully, it will be self explanatory.
 
== Code ==
Here's the code example that I came up with while working out how to compose hiearchies, and "aquire" objects from parent components in PEAK. It requires the current CVS version of PEAK (0.5a3).
Here's the code example that I came up with while working out how to compose hierarchies, and "aquire" objects from parent components in PEAK. It requires the current CVS version of PEAK (0.5a3).
 
{{{
#!python

    print "gc.myColor: ",gc.gcColor
    print "gc.gcStr: ",gc.gcStr
    print "done"
 
}}}
 
 

{{{
[joel@banzai playground1]$ python components1.py
c.eggs: othereggs
c.eggs: spam
c.spam: spam
c.cStr: simple-c!
gc.spam: spam
gc.eggs: eggs

 
 
--Joel Boehland
 
= Discussion =
 
So, it seems to me:
 
{{{
#!python
class SimpleCmp(binding.Component):
    __eggs = binding.Make(Eggs, offerAs=[IEggs, EGGS_PROPERTY])
}}}
 
This means: "When you make a SimpleCmp, it has within it a variable __eggs. __eggs is an Eggs. When someone asks for the SimpleCmp's IEggs interface, patch it through to my internal __eggs. And when they ask for the SimpleCmp's EGGS_PROPERTY, also patch them through to my internal __eggs."
 
It also seems that: If a component has another component within it, that if the child component requests an interface, it firsts check ''locally'' for it, and if it's not found locally, it checks it's ''parent'' for it. And if not there, still higher up the chain (grandparent.)
 
Am I understanding right?
 
Next, I naturally wonder: "What for? What kinds of things do you get from this?" I'm not saying there isn't, I'm just not used to thinking this way. I'd like to get excited about it, by understanding what it can do for me.
 
-- LionKimbro [[DateTime(2005-04-17T13:58:41)]]
 
I think it is done to have a flexible InversionOfControl mechanism. That is the wiring between elements is made "magicaly". It's very flexible since you can change a piece with another without worrying to change the code of objects using it or an object doesn't have to know which object uses it.
 
-- AlexG [[DateTime(2005-05-12T14:30:00)]]

PythonPowered
ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck