| Start |
|---|
| Defining a class Classes are vital aspects of OOP. A class is like the "blueprint" of an object. An object has the properties of a class, but the characteristics are not defined within the class itself. As each object can be different, they define their own characteristics. A class can also contain subclasses. A subclass inherits the same properties and behaviors as its parent class, but can have its own unique properties and classes. |
Inheritance Modifiers (on classes) InheritsSpecifies the base (or parent) class Possible objects: NotInheritablePrevents programmers from using the class as a base class. Possible objects: MustInheritSpecifies that the class is intended for use as a base class only. (Abstract class) Possible objects: |
Inheritance Modifiers (on properties and methods) OverridableAllows a property or method in a class to be overridden in a derived class. OverridesOverrides an Overridable property or method defined in the base class. NotOverridablePrevents a property or method from being overridden in an inheriting class. Default behaviour. Can only be declared on overrides methods Example Usage: Output: MustOverrideRequires that a derived class override the property or method. MustOverride methods must be declared in MustInherit classes. Example Usage: Output: |
| MyBase The MyBase keyword behaves like an object variable that refers to the base class of the current instance of a class. Usage example: Output: |
| Me vs MyClass Me uses the current object instance. MyClass uses the memberdefinition in the class where the member is called Example Usage: Output: |
| Overloading Overloading is the creation of more than one procedure, instance constructor, or property in a class with the same name but different argument types. |
| Shadows It redeclares a member that is not overridable. Only calls to the instance will be affected. Code inside the base classes will not be affected by this. Example usage: Output: Pitfalls: Example1, Creating a new object through a generic. Which function will be used?? example usage: Output: By intuition the result should be the same. Yet that is not true. Example 2: Output: By intuition you could think that p and s are equal and will behave equal. Yet that is not true. In this simple examples it is easy to learn the strange behaviour of Shadows. But in real-life it brings a lot of surprises. It is advisably to prevent the usage of shadows. One should use other alternatives as much as possible (overrides etc..) |
Interfaces |
Read Article
https://develop.horje.com/learn/1434/reference