Skip to content

Instantly share code, notes, and snippets.

@mikemimik
Last active September 20, 2015 01:16
Show Gist options
  • Save mikemimik/b572fce6436fb694ea16 to your computer and use it in GitHub Desktop.
Save mikemimik/b572fce6436fb694ea16 to your computer and use it in GitHub Desktop.
Object Oriented Programming Examples
/// <summary>
/// Base class that Generalizes Vehicles.
/// </summary>
public class Vehicle {
/// <summary>
/// Every vehicle has an Identification Number.
/// </summary>
protected string VIN { get; set; }
/// <summary>
/// Every vehicle has a make.
/// </summary>
protected string Make { get; set; }
/// <summary>
/// Every vehicle has a model.
/// </summary>
protected string Model { get; set; }
}
/// <summary>
/// A specialization of Vehicle -- the TRUCK
/// </summary>
public class Truck : Vehicle {
/// <summary>
/// Classes of trucks are defined by towing capacity.
/// </summary>
public int TowingCapacity { get; set; }
/// <summary>
/// These are the protected attributes of Vehicle.
/// </summary>
public string Make {
get { return base.Make; }
set { base.Make = value; }
}
public string Model {
get { return base.Model; }
set { base.Model = value; }
}
public string VIN {
get { return base.VIN; }
set { base.VIN = value; }
}
}
/// <summary>
/// A specialization of Vehicle -- The CAR.
/// </summary>
public class Car : Vehicle {
/// <summary>
/// Not sure why someone wanted the car smell included -- but here it is!
/// </summary>
private string Smell;
/// <summary>
/// These are the protected attributes of Vehicle.
/// </summary>
public string Make {
get { return base.Make; }
set { base.Make = value; }
}
public string Model {
get { return base.Model; }
set { base.Model = value; }
}
public string VIN {
get { return base.VIN; }
set { base.VIN = value; }
}
}
Vehicle() {
var color;
var has_engine = null;
vehicle() {
this.color = 'blue';
}
}
Car() extends Vehicle {
var num_wheels;
car() {
this.num_wheels = 4;
}
}
Bike() extends Vehicle {
var num_wheels;
bike() {
this.num_wheels = 2;
}
bike(num_wheels) {
// What if we want 3 wheels?
this.num_wheels = num_wheels;
}
}
@mikemimik
Copy link
Author

var my_bike = new Bike();

var tricycle = new Bike(3);

var my_car = new Car();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment