# Inherited properties cannot be overridden

**URL:** <https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086>\
**Category:** Getting Started\
**Created:** [June 24, 2013, 1:23pm UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086 "2013-06-24T13:23:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alwyn\_Bester](https://forum.xojo.com/user_avatar/forum.xojo.com/alwyn_bester/32/23099_2.png) [@Alwyn\_Bester](https://forum.xojo.com/u/Alwyn_Bester)\
**Post date:** [June 24, 2013, 1:23pm UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/1 "2013-06-24T13:23:48Z")

</div>

I was just wondering out of curiosity, is there a reason why Xojo prevents the overriding of properties in a subclass?

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [June 24, 2013, 1:51pm UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/2 "2013-06-24T13:51:12Z")

</div>

Can you give an example?

---

<div class="post-metadata">

**Author:** ![Joe\_Ranieri](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@Joe\_Ranieri](https://forum.xojo.com/u/Joe_Ranieri)\
**Post date:** [June 24, 2013, 1:58pm UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/3 "2013-06-24T13:58:50Z")

</div>

> [@16084:@Alwyn Bester](#):
>
> I was just wondering out of curiosity, is there a reason why Xojo prevents the overriding of properties in a subclass?

There isn’t actually overriding, just shadowing (which is bad, please don’t do that). It’s possible that computed properties could someday be made virtual, but then you could end up with a fragile implementation that depends on your superclass never changing their property to be non-computed (or to a getter/setter pair of methods).

---

<div class="post-metadata">

**Author:** ![Alwyn\_Bester](https://forum.xojo.com/user_avatar/forum.xojo.com/alwyn_bester/32/23099_2.png) [@Alwyn\_Bester](https://forum.xojo.com/u/Alwyn_Bester)\
**Post date:** [June 24, 2013, 2:04pm UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/4 "2013-06-24T14:04:52Z")

</div>

> [@16091:@Greg Olone](#):
>
> Can you give an example?

1. In a new project create a new class named “Class1”
2. Add a property named “ABC” of type Integer to Class1.
3. Now create a second class named “Class2” that has Class1 as its super.
4. Add a property named “ABC” of type String to class 2
5. Run the project and the error shows “This property shadows a property of a different type”.

> [@16092:@Joe Ranieri](#):
>
> There isn’t actually overriding, just shadowing (which is bad, please don’t do that). It’s possible that computed properties could someday be made virtual, but then you could end up with a fragile implementation that depends on your superclass never changing their property to be non-computed (or to a getter/setter pair of methods).

Thanks for clarifying this Joe.

I’ve never attempted this, and never had a need to do so either. Myself and a colleague are just comparing Xojo with other languages, and he posed this question to me, and I wasn’t too sure how to answer him.

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 2, 2013, 1:06am UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/5 "2013-12-02T01:06:54Z")

</div>

if you take a class like “TestGroup” from the Xojo Unit Testing. and you subclass it to add additional features. One of the properties of TestGroup is of type TestResults. But if you subclass TestResults too to add extra functionality, you cant tell your subclass of TestGroup to have the properties of your subclassed TestResults.

for instance.

```auto
TestGroup.CurrentTestResult is a TestResult
```

I would want it to be…

`MyTestGroup.CurrentTestResult is a MyTestResult
`  
where as MyTestGroup is a subclass of TestGroup, and MyTestResult is a subclass of TestResult.

this is good so when Xojo updates the Xojo Unit Testing suite, I just have to drop it in and it works. I am not modifying the original code to extend it.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 2, 2013, 1:30am UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/6 "2013-12-02T01:30:00Z")

</div>

[quote=16095:@Alwyn Bester]  
I’ve never attempted this, and never had a need to do so either. Myself and a colleague are just comparing Xojo with other languages, and he posed this question to me, and I wasn’t too sure how to answer him.[/quote]  
It helps avoid one of the issues in the “fragile base class” problem  
It doesn’t get rid of it entirely though  
However IF you want “virtual properties that can be overridden” use a pair of methods using assigns for the setter & then you can override those in subclasses.  
Fortunately Xojo makes it easy to change an implementation from an exploded public property to computed property to get/set pair with users of the class never having to change syntax.

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [December 2, 2013, 1:16pm UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/7 "2013-12-02T13:16:30Z")

</div>

You can actually override a property: in the code of the subclass’s property you need to cast Self to the superclass type instead of using the Super keyword. But it is not recommended (and therefore not documented) - it is not future safe.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 2, 2013, 4:11pm UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/8 "2013-12-02T16:11:43Z")

</div>

> [@50314:@Eli Ott](#):
>
> You can actually override a property: in the code of the subclass’s property you need to cast Self to the superclass type instead of using the Super keyword. But it is not recommended (and therefore not documented) - it is not future safe.

If you declared it as a computed property with the same type & name as in the super that doesn’t override it - that shadows it.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 4:43pm UTC](https://forum.xojo.com/t/inherited-properties-cannot-be-overridden/9086/9 "2020-10-29T16:43:16Z")

</div>


