masking public property?
Posted: Sun Oct 25, 2020 12:32 pm
I want to have some factory methods.
A parameter of a shared method with the name of a instance property masks this property if it creates an instance.
In the sample code an instance created by #createWrong has a public field #name insted of a property.
In the sample ccde has an instance created by #createWrong a public field with the name
A parameter of a shared method with the name of a instance property masks this property if it creates an instance.
In the sample code an instance created by #createWrong has a public field #name insted of a property.
Code: Select all
:Class Text
∇ p←createOk name_
:Access Public Shared
p←#.⎕NEW ⎕THIS name_
∇
∇ p←createWrong name
:Access Public Sharedhave som [i][i][/i][/i]
p←#.⎕NEW ⎕THIS name
∇
:Field Private m_name←'unnown'
:Property name
:Access Public
∇ r←get
r←m_name
∇
:EndProperty
∇ make1 name
:Implements Constructor
:Access Public
m_name←⌽name
∇
∇ r←show;∆ok
:Access Public
∆ok←{≡/⍵:⍵,⊂'okay' ⋄ ⍵,⊂'wrong'}
r←(⊂'#name:'),∆ok m_name name
∇
:EndClass
In the sample ccde has an instance created by #createWrong a public field with the name
Code: Select all
(#.ok←Text.createOk'reteP').show
#name: Peter Peter okay
(#.wrong←Text.createWrong'luaP').show
#name: Paul luaP wrong
#.wrong.⎕NL¯2.1
name