Login  Register

Re: [Ann] New version of Ghost

Posted by Denis Kudriashov on Mar 24, 2016; 6:34pm
URL: https://forum.world.st/Ann-New-version-of-Ghost-tp4886357p4886371.html

Hi.
Thank's for kind words.

2016-03-24 19:22 GMT+01:00 Mariano Martinez Peck <[hidden email]>:
  • GHClassGhost able to replace class of real objects. It implements cannotInterpret: trick to intercept all instance messages. Subclasses should define two behaviours: #ghostBehaviour (as any other ghost) and #instancesBehaviour which will process instance messages. In previous version it was different message to same #ghostBehaviour.

In your original version you implemented #cannotInterpert: for instance messages such way:
proxy proxyHandler handleInterceptionToInstance: interception.
And proxy handler was responsible for two messages: #handleInterceptionToInstance: and #handleInterception:. 
In my version I ask proxy for different kind of handler (ghostBehaviour):

GHObjectGhost>>doesNotUnderstand: aMessage
self ghostBehaviour intercept: aMessage to: self

GHInstanceMessagesInterceptor>>cannotInterpret: aMessage
"some logic to find ghostClass"
ghostClass instancesBehaviour intercept: aMessage to: self
 
  • New kind of proxies:
    • GHObjectVirus. It is special kind of GHClassProxy. It infects real object to intercept it messages. From meta level infected object looks like healthy object which means that meta messages are executed by infected object itself. As class virus looks like real victim class. So in case when virus is created with standard meta level tools will not differ him from health object. There are special messages which allow ask object about viruses:
      • infectedObject isInfectedByVirus
      • infectedObject virus
      • infectedObject recoverFromVirus

Sorry I did not get this one. 

Good example where I use viruses is stubbing real objects in Mocketry. I will announce it soon. You can do this:
rect := 0@0 corner: 2@3
rect stub area willReturn: 1000.

rect area "=> 1000".
rect origin "=> 0@0".

From any tool you will see normal rectangle. Nothing special. But in reality it is infected by virus which delegate all messages to "Mocketry machinery". And you can detect it by:
rect isInfectedByVirus "=> true"
And you can heal infected object:
rect recoverFromVirus. "or virus heal: infectedObject"
rect isInfectedByVirus "=> false"