1. Introduction to Object-Oriented Concepts


Additional Points:

UML Class Diagram

I use the UML Class Diagram during the whole presentation. It is color coded and used three distinct colors; Blue, Green, and Orange.

  • Blue: Is the name of the Class.
  • Green: Is all the attributes the class will have.
  • Orange: Is all the methods the class will have.

Do not worry too much about the code or diagrams we use. Right now we are focusing on the concepts and theory. We will cover diagrams in another lesson.

Best Practice

  • Classes should be defined as one 'thing'.
    • Example: A RegisteredUser and VisitorUser should extend a Super Class named User and RegisteredUser and VisitorUser should have their own unique properties that are not shared through their Super Class User.
  • Methods should focus on one task and every task should keep it's 'process' private.
/*
*Consider these two methods: addNumbers() and returnSum(). 
*addNumbers() should be set private and be used inside returnSum(). 
*returnSum() is only expecting a value which it will return 
-but in itself does not handle how the numbers are added.
*/
private function addNumbers($number1, $number2){
    return $number1 + $number2;
}

public function returnSum($number1, $number2){
    return addNumbers($number1, $number2);
}
  • Classes and Table Example: Think of the whole table with all its columns as a class. Every table can have multiple rows. Think of the rows as Objects. Each table can have multiple rows just like a single class can have multiple objects.


Download Lesson Notes

The Object-Oriented Thought Process

Author: Matt Weisfeld