masking public property?
3 posts
• Page 1 of 1
masking public property?
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
- Manuel Kassens
- Posts: 2
- Joined: Wed Apr 22, 2020 2:17 pm
Re: masking public property?
I think this is just how it is and that you will need to use different names.
Compared to:
- Code: Select all
:Class C
:field public name
∇ Init name
:Access public
:Implements constructor
name←name
∇
:EndClass
- Code: Select all
c←⎕NEW C 'John'
c.name
VALUE ERROR
c.name
∧
Compared to:
- Code: Select all
:Class C
:field public name
∇ Init arg
:Access public
:Implements constructor
name←arg
∇
:EndClass
- Code: Select all
c←⎕NEW C 'John'
c.name
John
- RichardP|Dyalog
- Posts: 33
- Joined: Fri Oct 12, 2018 3:05 pm
Re: masking public property?
Surely this must be a bug? I understand that the name is shadowed while createWrong is on the stack, but it seems that the instance created with createWrong has managed to change the property name into a variable type. Setters and getters are no longer triggered at all?!
(#.ok←Text.createOk'reteP').show
#name: Peter Peter okay
ok.⎕NC⊂'name'
¯2.3
(#.wrong←Text.createWrong 'reteP').show
#name: Peter reteP wrong
wrong.⎕NC⊂'name'
¯2.1
- gil
- Posts: 72
- Joined: Mon Feb 15, 2010 12:42 am
3 posts
• Page 1 of 1
Return to Object Oriented Programming
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group