Category Archives: Object Oriented Programming

Object Oriented Design 11

Object Oriented Design 11In this tutorial I finish covering the GRASP patterns I covered previously here GRASP Tutorial.

This time talk about Polymorphism, Indirection and Protected Variations. They show how you can create flexibility in your system in different ways by having different classes implement interfaces. I also talk about Pure Fabrication, which shows the importance of separating out code that impedes low coupling. Code follows the video to help you.

Continue reading Object Oriented Design 11

Object Oriented Design 10

Object Oriented Design 10In this tutorial, I cover GRASP, or General Responsibility Assignment Software Patterns. GRASP defines rules you can use to decide which objects should have which responsibilities in your Object design.

Here I cover the following rules: Creator, Expert, Coupling, Controller and High Cohesion. The tutorial includes a presentation, code examples, sequence diagrams and class diagrams to make everything understandable and interesting. The code used follows the video.

Continue reading Object Oriented Design 10

Object Oriented Design 9

Object Oriented DesignWelcome to part 9 of my Object Oriented Design tutorial! This all started back in part 3 in my UML Use Case Tutorial.

Here I’ll finish turning sequence diagrams into code. If you get good at this process you’ll be able to make any program no matter how complicated it may be.

All of the code from this and the last tutorial can be found below to help you learn. In the tutorials that follow I’ll answer all of the design pattern tutorials I’ve been receiving. Continue reading Object Oriented Design 9

Object Oriented Design 8

Convert Sequence Diagram into CodeI showed you how to turn your program idea into a Use Case. Then we turned the Use Case into a Domain Model. Then I showed you how to turn the Use Case into a Sequence Diagram. Then we made the Sequence Diagram into a Class Diagram. Now I’m going to show you how to convert the Sequence Diagram into working code.

I make part of the code in this video. The rest will be made in part 9 of my Object Oriented Design Tutorial. All of the code follows the video to help you learn. To get the other diagrams, just click the associated links above.

Continue reading Object Oriented Design 8

UML Video Tutorial

UML Video TutorialUnified Modeling Language (UML) is a graphical way of describing software systems. In this tutorial series, I cover Use Case, Activity, Class, Object, Sequence and many more UML Diagrams.

I can’t think of anything more important for a good programmer to understand than UML. With it you’ll be able to create first class Object Oriented Designs. Those designs will allow you to create anything you can imagine. But, without UML none of these things are possible. Every video and links to all of the code can be found below.

Continue reading UML Video Tutorial

Object Oriented Design 7

Convert Sequence Diagram to Class DiagramIn previous tutorials I showed you how to make a sequence diagram. In this video, I’ll show you how to convert a Sequence Diagram into a Class Diagram. Here are the tutorials on making sequence diagrams if you missed them OOD Sequence Diagrams & Sequence Diagrams 2.

In this tutorial, I wanted to show step-by-step how sequence diagrams are turned into class diagrams. Then in the next video, I’ll turn them both into working code in about 10 minutes. The class diagrams used can be found below.

Continue reading Object Oriented Design 7

Object Oriented Design 6

Object Oriented Design Sequence DiagramIn the last tutorial, I showed you how to create a complicated sequence diagram for our ATM software. In this tutorial, I’m going to simulate the process of creating a sequence diagram in a group atmosphere.

I’ll improve the last design, while explaining what I’m thinking. I’m also trying to teach how to think through a programming problem while creating the sequence diagram.

Both new sequence diagrams follow the video to help you learn. Continue reading Object Oriented Design 6

Object Oriented Design 5

Object Oriented Design Sequence DiagramIn this video I continue building my ATM software using Object Oriented Design principles. If you missed the beginning of this tutorial, the previous videos are here.

If you want to learn everything about Sequence Diagrams, I have you covered as well. I take you through the creation of a sequence diagram using all of the diagrams I made before it. The sequence diagram made in the video follows the video to help you learn. Continue reading Object Oriented Design 5

Object Oriented Design 4

Object Oriented Design Domain ModelWelcome to the 4th part of my Object Oriented Design tutorial. I show you how to plan your first iteration. I explain all of the parts of the Elaboration phase of Object Oriented Design.

Then I take the Usage Case I made in part 3 of this tutorial, and convert it into a Domain Model. I cover all of the following: conceptual classes, how to build domain models, turning nouns into classes, associations and how to tell an attribute from a class.

This is a big tutorial, but the diagram that follows the video will help you learn this stuff.

Continue reading Object Oriented Design 4

Object Oriented Design 3

Object Oriented Design 3Welcome to my 3rd tutorial on Object Oriented Design. In this part of the tutorial, I’ll cover Iterative Development, The Unified Process and Usage Cases.

Unlike the waterfall process for object design, with the iterative process programming starts before all of the requirements are expected. The Unified Process is a popular IDP which focuses on high risk / value parts first before creating full requirements for the program.

A large Usage Case follows the video to help you.

Continue reading Object Oriented Design 3

Object Oriented Design 2

Object Oriented DesignIn the previous part of my Object Oriented Design Tutorial, I showed you how to build a Use Case, Object Model, Sequence Diagram and Class Diagram from scratch.

In this tutorial, I show you how to turn those diagrams into code and a working program. This is the process a person goes through to create excellent Object Oriented Designs. The code follows the video along with the digrams from last time.

Continue reading Object Oriented Design 2

Object Oriented Design Tutorial

Object Oriented Design TutorialWelcome to my Object Oriented Design Tutorial! I cover a ton of things in the video below.

The goal of this tutorial is to teach you how to create excellent OO designs. In this tutorial, I start off with a programming idea and walk you through the process of creating a Use Case, Object Model, Sequence Diagram and Class Diagram.

If you need help understanding sequence diagrams look here. The diagrams that follow the video should help you along though.

Continue reading Object Oriented Design Tutorial

Web Design and Programming Pt 11

Object Oriented ProgrammingHere I continue to explain Object Oriented Programming with PHP. If you missed the first part definitely watch that video tutorial first Object Oriented Programming with PHP.

Here I’ll cover the following topics:

  • Inheritance
  • Static Attributes (Variables)
  • The _destruct Function
  • The Final Keyword
  • Overriding Functions
  • And more…

If you have any questions, leave them below. All of the code follows the video.

All the Code from the Video

<html>
<head>
<title><?php echo “Object Oriented Programming”;?></title>
</head>

<body>

<?php

# Inheritance is done when you create a new class from another, thus borrowing the data
# and methods that can be found there.

class Animal
{
private $name; # Private variables are only accessed by class methods, but not subclasses
private $favFood = “meat”;

# A static attributes value is shared by all objects of the class
# You refer to static attribute like this self::$numOfAnimals, not with $this
public static $numOfAnimals = 0;

# Constructor and Deconstructor
public function __construct($name=”No Name”)
{
echo “__construct was called”. “<br />”;
$this->setName($name);
self::$numOfAnimals++;
}

public function __destruct()
{
echo “__destruct was called”. “<br />”;
}

# Get and Set Methods – final is used to keep methods from being overwritten
final public function getName()
{
return $this->name;
}

final public function setName($sentName)
{
$this->age = $sentName;
}

# Animal Default Functions
public function makeNoise()
{
echo “Grrrr”. “<br />”;
}
public function favFood()
{
echo “My favorite food is ” . $this->favFood . “<br />”;
}
public function move()
{
echo “Walk around”. “<br />”;
}

}

class Dog extends Animal
{
# If I didn’t create a new constructor the parent would be called
public function __construct($name=”No Name”)
{
parent::__construct($name); # How to call the parent constructor
# Animal::__construct($name); this would also call the parent constructor
}

public function __destruct()
{
echo “__destruct was called”. “<br />”;
}

# Dog Default Functions Overwrites Class Function
public function makeNoise()
{
Animal::makeNoise(); # How to call the original class method
echo “Bark, Bark”. “<br />”;
}
}

#function animalStuff(

$grover = new Dog(“Grover”); # Create an object grover of class Dog
$paul = new Dog(“Paul”);
$grover->makeNoise(); # Call the makeNoise() method for the grover object
$grover->favFood();
$grover->move();

echo Animal::$numOfAnimals. “<br />”; # Prints out the number of objects created

?>

</body>
</html>

Web Design and Programming Pt 10 OOP & PHP

Object Oriented ProgrammingIn this PHP video tutorial I cover Object Oriented Programming with PHP. I specifically go over the following topics:

  • Encapsulation
  • Classes
  • Objects
  • Public
  • Private
  • Constructors
  • Destructors
  • __set
  • __get
  • And more….

All of the code from the tutorial is available after the video. Use it in anyway that you like. I’ll continue covering OOP with PHP in the next video tutorial in this series.

If you have any questions leave them below.

All the Code from the Video

<html>
<head>
<title><?php echo “Object Oriented Programming”;?></title>
</head>

<body>

<?php
# Encapsulation lets you hide the code behind an interface so you can protect the code
# and so your user need not understand the code to use it

# A class is a blueprint you use to create objects

# Objects contain the data (attributes) and actions (methods) needed to perform its tasks

# Inheritance is done when you create a new class from another, thus borrowing the data
# and methods that can be found there.

# Polymorphism allows a class to perform differently based on how it is being used.
# Polymorphism can be used to a certain extent with PHP in that you can use common
# method and attribute names for similar classes

# Any use of this is a reference to a specific object and that objects attributes and methods

class Animal
{
public $name; # Public variables can be accessed directly by anyone
private $age; # Private variables are only accessed by class methods, but not subclasses
protected $money; # Protected is like private except can be accessed by inherited classes
const POUNDID = 12345; # A constants value can never change
# A static attributes value is shared by all objects of the class
# You refer to static attribute like this self::$numOfAnimals, not with $this
private static $numOfAnimals = 0;

public function __construct($age)
{
echo “__construct was called”. “<br />”;
$this->setAge($age);
}

public function __destruct()
{
echo “__destruct was called”. “<br />”;
}

# __set can be used to perform error checking before assigning values to private attribs
function __set($attribName, $attribValue)
{
echo “__set was called for “. $attribName. “<br />”;
$this->$attribName = $attribValue;
}

# __get can be used to perform error checking before returning values from private attribs
function __get($attribName)
{
echo “__get was called for “. $attribName. “<br />”;
return $this->$attribName;
}

public function getAge()
{
return $this->age;
}

public function setAge($sentAge)
{
$this->age = $sentAge;
}
}

$dog = new Animal(8); # Create an object dog of class Animal
$dog->name = “Grover”; # Assign a value to the public attribute name
$dogName = $dog->name; # Retreive value from public attribute name

$dog->setAge(8); # Call the setAge() method for the dog object

$dog->age = 9; # Try to set a private attribute that makes a call to __set
echo $dog->age. “<br />”; # Try to get a private attribute that makes a call to __get

echo “The dogs name is ” . $dogName . “<br />”;
echo “The dogs age is ” . $dog->getAge() . “<br />”;
echo “The pounds ID number is “. $dog::POUNDID. “<br />”;

?>

</body>
</html>

What is Object Oriented Programming

[youtube]http://www.youtube.com/watch?v=OQjPcS1tkDQ[/youtube]Welcome to a brief tutorial on what is Object Oriented Programming (OOP) and why the object oriented approach is considered the best way to program. Objects programming has taken the world by storm because of its flexibility and understandability, but learning the concepts behind it are sometimes a bit daunting. I will do my best to explain it in the simplest of terms. I assume you have a minor understanding of programming in this article, but if not, you can read my Javascript Scripting Tutorial to get prepared.

What Are Objects in Object Oriented Programming

A while back when a programmer sat down to write a program he/she would first ask “What does this program have to do?” They would then create a program that was filled with one action after another. This is known as procedural programming.

Now most programmers instead ask themselves, “What things are in this program?” Then they write code that explains what functions these things (objects) should be able to do. This is known as Object Oriented Programming (OOP).

Let’s say you are told to create a program that copies the functionality of a car. Here is a basic example of how you might do that with procedural programming versus OOP. Continue reading What is Object Oriented Programming