CS3340:  Intro OOP and Design

Overview of OOP

OOP = Object Oriented Programming.

Objectives:

What is OOP?

Language-Level Definition

  • Class
  • Object
  • Inheritance
  • Interface

Conceptual-Level Definition




Class = a template representing a self-contained element of a computer program (i.e. a module) that represents related information and has the cability to accomplish specific tasks through the invokation of methods.


Object = a particular instance of a class.

Instance = same thing as Object.

An OO Program = A set of classes, pluseobjects created from those classes and used as needed.

class library = group of classes that you can use in your own program. In Java, we also call this a package (a group of related classes).

  • Packages in java are called java.*
  • by default, your java classes have access only to the pacakage java.lang You must refer to other classes explicitly ( e.g. java.awt.Color) or import the package and then just use the classname.



Example
Dog Class and Instances
Dog Class and several Dog objects/instances




Inheritance

  • a mechanism that enables one class to inherit all the behaviors and attributes of another class.


subclass = a class that inherits from another class.

superclass = a class that is its inheritance to another class. Example
heirarch of animal classes
Hierarchy of Animal Classes.


Note: Subclasses can override methods they have inherited if they want to change the corresponding behavior. For example, the method to calculate the Expected Lifespan for each Class of Dog, Cat, and Horse may be different from thier superclass Four-Legged Animal.



Interfaces

  • is a collection of methods that indicate a class has some behavior in addition to what it inherits from its superclasses
  • It is the way that a set of method names, without definitions. By this I mean the method's interface is presented but not implemented. This will allow similar behavior to be duplicated acrros different parts of the class hierarchy which is achievable in C++ through multiple inheritance which Java does not allow.
  • Can not declare an object of this class....must create a new class that extends this and implements all of the unimplemented methods.

Summary

from Budd book

1. Everything is an Object (in pure OOP)

2. Computation is done via Objects Communicating with each other by requesting objects to perform actions.

At some point at least a few object need to perform some work besides passing on requests to other objects/agents.


 
3. Each Object has its own memory (and in pure OOP consists of other objects)

 

4. Every object is an instance of a class.

5. A Class is a repository for behavior associated with an object and the kind of information stored in an instances memory.

6. Classes are organized into a single rooted tree structure. Memory and behavior of an instance of a class is automatically available (inheritance) to any class associated with a descendant.

 

 

© Lynne Grewe