How to resolve the algorithm Break OO privacy step by step in the PicoLisp programming language
How to resolve the algorithm Break OO privacy step by step in the PicoLisp programming language
Table of Contents
Problem Statement
Show how to access private or protected members of a class in an object-oriented language from outside an instance of the class, without calling non-private or non-protected members of the class as a proxy.
The intent is to show how a debugger, serializer, or other meta-programming tool might access information that is barred by normal access methods to the object but can nevertheless be accessed from within the language by some provided escape hatch or reflection mechanism.
The intent is specifically not to demonstrate heroic measures such as peeking and poking raw memory.
Note that cheating on your type system is almost universally regarded
as unidiomatic at best, and poor programming practice at worst.
Nonetheless, if your language intentionally maintains a double-standard for OO privacy, here's where you can show it off.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Break OO privacy step by step in the PicoLisp programming language
Source code in the picolisp programming language
(class +Example)
# "_name"
(dm T (Name)
(=: "_name" Name) )
(dm string> ()
(pack "Hello, I am " (: "_name")) )
(====) # Close transient scope
(setq Foo (new '(+Example) "Eric"))
: (string> Foo) # Access via method call
-> "Hello, I am Eric"
: (get Foo '"_name") # Direct access doesn't work
-> NIL
: (get Foo (loc "_name" +Example)) # Locating the transient symbol works
-> "Eric"
: (put Foo (loc "_name" +Example) "Edith")
-> "Edith"
: (string> Foo) # Ditto
-> "Hello, I am Edith"
: (get Foo '"_name")
-> NIL
: (get Foo (loc "_name" +Example))
-> "Edith"
You may also check:How to resolve the algorithm Unicode variable names step by step in the Rust programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the GW-BASIC programming language
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Haskell programming language
You may also check:How to resolve the algorithm Horizontal sundial calculations step by step in the F# programming language
You may also check:How to resolve the algorithm Gaussian elimination step by step in the C# programming language