Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SD&D 101

SD&D 101

OOP basics

Kevin O'Connor

February 26, 2014
Tweet

More Decks by Kevin O'Connor

Other Decks in Technology

Transcript

  1. string[] firstNames;! string[] lastNames;! ! string getName(string[] fNames, string[] lNames,

    int i)! {! "return fNames[i] + " " lNames[i];! }! Why? This is bad.
  2. class Student {! "public string getName() { return firstName+” “+lastName;

    } ! ! "private string firstName;! "private string lastName;! "private int gradeLevel;! }!
  3. interface IPerson {! "public string getName();! }! ! class Student

    : IPerson {! "public string getName() { return firstName+" “+lastName; } ! ! "private string firstName;! "private string lastName;! "private int gradeLevel;! }! All members must be implemented
  4. class Person {! "public string getName() { return firstName+" "+lastName;

    } ! ! "private string firstName;! "private string lastName;! }! ! class Student : Person {! "private int gradeLevel;! }! ! class Professor : Person {! "private string department;! }!
  5. class Person {! "public string getName() { return firstName+" "+lastName;

    } ! ! "private string firstName;! "private string lastName;! }! ! class Student : Person {! "private int gradeLevel;! }! ! class Employee : Person {! "private in employeeId;! }! ! class TA : Employee, Student {! "private string department;! }! An object can Inherit from multiple
  6. Okay, But Why? Makes your code readable Avoids redundant code

    Keeps like things organized Avoids pollution