1 / 7

Object-Oriented Programming Concepts Illustrated

Understand inheritance, polymorphism, abstract classes, and templates through practical examples in building class hierarchies. Learn how these concepts can enhance code reusability and flexibility.

kirsi
Download Presentation

Object-Oriented Programming Concepts Illustrated

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Agenda • Inheritance • Polymorphism • Abstract • Template Classes

  2. 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

  3. Inheritance Example • This class Triangle will inherit properties/methods from the class Polygon public class Triangle : Polygon { // class details go here }

  4. 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

  5. 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

  6. 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>

  7. Template Example class Point2D<T> { public T X; public T Y; public override string ToString(){ return “(“ + X.ToString() + ”, “ + Y.ToString() + ”)”; }

More Related