70 likes | 142 Views
Agenda. Inheritance Polymorphism Abstract Template Classes. Inheritence. Create a class that uses properties from another class Basically you create a copy of a class, and some of the properties are “copied” for you. Inheritance Example.
E N D
Agenda • Inheritance • Polymorphism • Abstract • Template Classes
Inheritence • Create a class that uses properties from another class • Basically you create a copy of a class, and some of the properties are “copied” for you
Inheritance Example • This class Triangle will inherit properties/methods from the class Polygon public class Triangle : Polygon { // class details go here }
Polymorphism • This is the idea that one function can do similar things for different objects. • We have already seen this with ‘+’: • s = “hello” + “ everybody”; • x = count + 2; // string and int use ‘+’ differently • Sometimes we have to use “override” if a function is already defined
Abstract • These are methods and variables to be defined and fleshed out in inherited classes. • Common Abstract methods are: • ToString(); • Draw(); • This is a way to create a class property that is dependent on the specifics of the child class
Templates • We can create a Point2D class for int points • So we can create: • Point2DInt • Point2DFloat • Point2DDouble • Point2DUInt • Or we can create a Template • Point2D<T>
Template Example class Point2D<T> { public T X; public T Y; public override string ToString(){ return “(“ + X.ToString() + ”, “ + Y.ToString() + ”)”; }