OO Confidence Course

Right now some of my team is in Object-Orienteed Analysis and Design training.  They appreciate that they are learning the concepts.  However, the instructor has not presented them with code in any language.  Therefore, we are going to do an "OO Confidence Course."  The idea is that we will briefly discuss the foundations of OO, look at the language specific implementation and then work through implementing the concepts in code.

This VB.Net and C# comparison guide from Frank McCown will provided to serve as a handy reference to language specific constructs.

If you are working to learn OO on your own or want an additional book to read on the topic that includes code, I can recommend Head First Object Oriented Analysis and Design.

After an initial session with this course, it's likely that someone new to OO would likely take around 4 hours to complete this confidence course.  I think an experienced developer could rapidly complete this course.

At a later date, in the course of professional duties, would be a good time to look at defining properties in an interface, CRC cards and unit tests.  The purpose of this exercise is to build OO confidence, so we're working hard to avoid "scope creep."  Also, because this is an exercise we ended up having an abstract Person and Concrete Person classes.  We needed to create the concrete class that others inherit from so we can show off the inheritance polymorphism in the demo section.  It's also significant to note that when demonstrating the interface polymorphism that the student class does not inherit from another class.

Here is the "OO Confidence Course"

 OO Confidence Course

For Group Discussion

  • What is polymorphism?
  • How does inheritance work?
  • Why do we use encapsulation?
  • Language specific discussion
  • C# this/subclass, base/superclass

Abstract Person class

This class should have properties/accessors/mutators for:

  • Age
  • Gender
  • Name

Override ToString method to display name and age

Create an abstract method ContactPhoneNumber that returns a string

Concrete Person class

Inherits from Person

Implements the abstract method ContactPhoneNumber
    Return "123-555-1212" for the phone number


Diagram and create an employee class that inherits from ConcretePerson

This class should have properties/accessors/mutators for:

  • ID #
  • Job Title

The constructor should give the person a default ID of -1 and a blank title, age, gender and name

Overload the constructor to accept an ID#, Title and Name

Override the ToString method of employee to display the data in all of the fields

Create a method that calls the base/superclass toString()  - call it superToString

Implement the abstract method ContactPhoneNumber
    Return "987-444-3535" for the phone number

Create an Interface called IStatusInfo

The interface definition should require a method isEmployable that returns a boolean


This class inherits from person

Implements the IStatusInfo interface (return true)


This class has a single property of name

Implements the IStatusInfo Interface  (return false)

Demo Program - Console application

Create an array/arraylist of ConcretePerson objects

Populate the arraylist with data

  • 3 employee objects
  • 2 Citizen objects

Loop through all of your person objects

  • print the base/superclass toString (does this work?)
  • print the this/subclass toString
  • Print the ContactPhoneNumber

For one employee object

  • print the base/superclass toString (does this work?)
  • print the this/subclass toString
  • print the string returned by superToString 

Create 4 IStatusInfo objects

  • Set them equal to the 2 citizens you created earlier + 2 students

Loop through all of the IStatusInfo objects

  • Print the result of the call to isEmployable

No comments:

Post a Comment