Last active
March 5, 2019 10:58
-
-
Save lordlycastle/4c34cbfcfec93db44bdd4ca538fd127c to your computer and use it in GitHub Desktop.
Why are OOP so convoluted in .NET?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Scripts | |
{ | |
public class BaseProperty : Object | |
{ | |
public int myInt = 1; | |
} | |
// An abstract class that can be inherited. | |
public class BaseClass | |
{ | |
public BaseProperty myProperty = new BaseProperty(); | |
public BaseClass() | |
{ | |
Console.WriteLine($"Base class: {myProperty.myInt}"); | |
} | |
} | |
public class DerivedProperty : BaseProperty | |
{ | |
public int myDerivedInt = 2; | |
} | |
// A sub type of abstract class which will be inherited. | |
public class DerivedClass : BaseClass | |
{ | |
public new DerivedProperty myProperty = new DerivedProperty(); | |
public DerivedClass() : base() | |
{ | |
Console.WriteLine($"Derived class: {myProperty.myInt}, {myProperty.myDerivedInt}"); | |
} | |
} | |
public class UseableDerivedProperty : DerivedProperty | |
{ | |
public int myUseableInt = 3; | |
} | |
public class UseableDerivedClass : DerivedClass | |
{ | |
public new UseableDerivedProperty myProperty = new UseableDerivedProperty(); | |
public UseableDerivedClass() : base() | |
{ | |
Console.WriteLine($"Useable derived class: {myProperty.myInt}, {myProperty.myDerivedInt}, {myProperty.myUseableInt}"); | |
} | |
} | |
public class UseableBaseProperty : BaseProperty | |
{ | |
public int myUseableInt = 2; | |
} | |
public class UseableBaseClass : BaseClass | |
{ | |
public new UseableBaseProperty myProperty = new UseableBaseProperty(); | |
public UseableBaseClass() : base() | |
{ | |
Console.WriteLine($"Useable base class: {myProperty.myInt}, {myProperty.myUseableInt}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment