Break OO privacy: Difference between revisions

Omit Zig
(Omit Zig)
 
(3 intermediate revisions by 3 users not shown)
Line 436:
Ecstasy security is accomplished by the use of <i>software containers</i>. Code running in a container is always allowed reveal any legal type on any object created within that container, including any object created within sub-containers. However, the runtime will reject any reveal request on any object that was <i>not</i> created within that container.
<syntaxhighlight lang="java">
module BreakOO {
{
/**
* This is a class with public, protected, and private properties.
*/
class Exposed {
{
public String pub = "public";
protected String pro = "protected";
Line 448 ⟶ 446:
 
@Override
String toString() {
{
return $"pub={pub.quoted()}, pro={pro.quoted()}, pri={pri.quoted()}";
}
}
{}
 
void run() {
{
@Inject Console console;
 
Line 483 ⟶ 479:
 
console.print($"after: {expo}");
}
}
}
</syntaxhighlight>
 
Line 1,461 ⟶ 1,457:
 
However, there is no such thing as a private method. Although conventionally methods which are not intended to be called from outside the class are suffixed with an underscore, this doesn't prevent anyone from accessing them as the following example shows.
<syntaxhighlight lang="ecmascriptwren">class Safe {
construct new() { _safe = 42 } // the field _safe is private
safe { _safe } // provides public access to field
Line 1,478 ⟶ 1,474:
84
</pre>
 
=={{header|zkl}}==
In zkl, privacy is more convention than enforced (unlike const or protected).
Line 1,509 ⟶ 1,506:
{{omit from|x86 Assembly}}
{{omit from|Z80 Assembly}}
{{omit from|Zig}}
{{omit from|ZX Spectrum Basic}}
{{omit from|Insitux}}
28

edits