Object Oriented Programming Advanced Usage – Arma Reforger
Lou Montana (talk | contribs) (Add private access to modded classes) |
Lou Montana (talk | contribs) m (Remove after class' semicolons) |
||
Line 23: | Line 23: | ||
Animal animal = cocker; // OK, as a cocker is an animal | Animal animal = cocker; // OK, as a cocker is an animal | ||
string sentence = cocker; // error: cocker does -not- inherit from string | string sentence = cocker; // error: cocker does -not- inherit from string | ||
} | } | ||
</enforce> | </enforce> | ||
Line 84: | Line 84: | ||
Print(m_data); | Print(m_data); | ||
} | } | ||
} | } | ||
</enforce> | </enforce> | ||
Line 115: | Line 115: | ||
Print(m_sPrivateString); | Print(m_sPrivateString); | ||
} | } | ||
} | } | ||
void Test() | void Test() | ||
Line 132: | Line 132: | ||
super.Say(); | super.Say(); | ||
} | } | ||
} | } | ||
void TestModded() | void TestModded() |
Revision as of 11:06, 19 May 2023
Casting
Casting is the act of "presenting" a value as another type. For example, if a class hierarchy is Animal > Dog > Cocker, a dog is an animal, a cocker is a dog (that is an animal), but a dog is not especially a cocker.
Upcasting
Upcasting means seeing the class as one of its parents:
Downcasting
Downcasting means seeing a parent class as a specific child - this must be done by manually casting:
Manual Casting
Template
A template is a class that allows a generic management for multiple types. Its methods cannot assume anything about the type.
Modding
A mod can inherit/replace an existing class with the use of the modded keyword.
It is used to inject inherited class into class hierarchy without modifying other scripts (especially suitable in modding). A modded class behaves like a class inherited from the original class (one can use super to access the original class) but also allows private methods and functions access and modification. When a modded class is declared, the modded class will be instanced instead of the original class. Only classes within the same module can be modded (to mod a class in e.g GameLib module, the modded class has to be placed in the GameLib module).