|
Posted by Steve on 11/15/07 14:23
"Csaba Gabor" <danswer@gmail.com> wrote in message
news:892b2933-e964-4f5a-bbb5-f8d822f8f48b@l1g2000hsa.googlegroups.com...
> Steve, thanks for your awesome exposition on VB interfaces, replete
> with example. This type of post is all too rare on the web.
>
> Csaba
wow! thanks. i'm glad it helped.
cheers.
> On Nov 14, 8:10 pm, "Steve" <no....@example.com> wrote:
>> "Alex" <d_key...@hotmail.com> wrote in message
> ...
>> a difference, yes. something that will make your code quit bombing and
>> still
>> get the Factory functionality...probably not. all an interface (IFactory
>> in
>> this case) is, is a contract...a definition of what *all usable* objects
>> that *implement* that interface will provide a caller, i.e. your php
>> code.
>> make sense? IFactory will provide you no other functionality than that.
>> here's an example in vb.
>>
>> public interface iFactory
>> public property foo as integer
>> end interface
>>
>> public class sawMill
>> implements iFactory
>> public property get foo() implements iFactory.foo
>> get
>> return 666
>> end get
>> set (byval value as integer)
>> # do nothing...however, set is *required*
>> # because iFactory is read/write
>> end property
>> public function saw()
>> debug.print "sawing..."
>> end function
>> end class
>>
>> public class brewery
>> implements iFactory
>> private myFoo as integer
>> public property get foo() implements iFactory.foo
>> get
>> return myFoo
>> end get
>> set (byval value as integer)
>> myFoo = value
>> end property
>> public function brew()
>> debug.print "brewing " & myFoo
>> end function
>> end class
>>
>> in the above, both completely unrelated classes (sawMill and brewery)
>> have
>> iFactory.foo as part of their definition. how they implement them is
>> different, but each must have a read and write foo.
>>
>> if i simply say:
>>
>> private myFactory as iFactory
>>
>> and then try:
>>
>> myFactory.foo()
>>
>> it will do nothing. myFactory is an interface that has no working parts.
>> however, if i do:
>>
>> private myFactory as iFactory = new brewery
>> myFactory.foo = 15
>>
>> i'll get somewhere. notice that the above works whether or not i set
>> myFactory to new brewery OR sawMill. both have a foo interface. however,
>> if
>> i continue the above code with:
>>
>> myFactory.saw()
>>
>> it'll blow up. both saw and brew are specific interfaces defined by each
>> class respectively...not by iFactory. let's say that myFactory is set
>> somewhere unbeknownst to me, how would i take specific action?
>>
>> public function factoryToString(byval factory as iFactory, byval fooValue
>> as
>> integer)
>> factory.foo = fooValue
>> if typeof factory is sawMill then
>> factory.saw()
>> end if
>> if typeof factory is brewery then
>> factory.brew()
>> end if
>> end function
>>
>> anyway...i think i got off track, but does that help you know that you're
>> going to have to get at an actual Factory object in the list...which
>> doesn't
>> solve your memory problem?
Navigation:
[Reply to this message]
|