Object Oriented Programming
Basically, OOP has 4 principles to follow:
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
How if we want to use the existing class in another project without creating from scratch? We can utilize inheritance principle in OOP. Create a new class that has our new functionality, but also reuse the Point class (example).
In this game, we need MapLocation class that being subclass from Point class. Create a new MapLocation
class.
class MapLocation : Point
{
public MapLocation(int x, int y) : base(x,y)
{
}
}
So, our MapLocation class will have an attribute like Point class. We use base
here because Point
class is MapLocation's base class.