23
Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College

Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College

Embed Size (px)

Citation preview

Object Oriented ProgrammingIntermediate VB

Doug Waterman

Fox Valley Technical College

What is OOP

A way of programming based on the things (objects) involved.

It’s a way to solve problems.

What is an object?

An object is a high-level design item.– If you are an architect, you deal with the following

objects• working space• foundation• plumbing • HVAC

– The architect doesn’t think about how the concrete for the foundation will be poured. This would be a lower level design item.

What is an object in programming? Objects are things.

– People– companies– employees– time sheets– ledger entries– business requirements

An object refers to the specific thing.

Elements of an Object Oriented System Abstraction Encapsulation Inheritance Polymorphism

Abstraction

Abstraction is used to identify the objects involved with a particular application.

Allows you to focus on the objects of an application and not on the implementation.

It exposes the design of a system without involving the technological issues.

Allows the users to become key participants in the design process.

Abstraction Example

Sees the tree as a place to perch.

Sees the tree as a place to .. well you know!

Sees the tree as a fun thing to climb.

Encapsulation

Building internal information (properties) and operating procedures (methods) into an object.

Internal information is held within the object. External procedures don’t know how a function performs.– Example: How does the cbo.Item.Add Method work

for a ComboBox? – We don’t care!

Inheritance

There are two types of inheritance.

Interface Inheritance What properties and methods will you expose to

programs that use your class? Implementation Inheritance

How will programs be able to access your class Read Only Read/Write

Polymorphism

Two or more classes can have the ability to have behaviors that are named the same, have the same basic purpose but different implementations.– Both an Instructor and a MicrosoftCEO object

will have a “CalculatePay” behavior but the implementation (underlying code) can be very different.

What are Classes

A class is a group of similar objects.– A cookie cutter would be an example of a class.

– The cookies that are made using the cookie cutter are objects.

– You eat the cookie (object) but not the cookie cutter (class).

– Each cookie starts out exactly like every other cookie. You adjust the size, shape, frosting and topping that go on the cookie. This makes the object unique.

Where Do Properties, Fields and Methods Fit In?

An object has properties and methods. The list of properties and methods define the class interface.– A command button in the toolbox is an example of a class.

– A command button you place on a form is an example of an object derived from a class.

Properties and Fields are the “nouns” of an object, they hold information.

Methods are the action items- the “verbs”.

Example Class

Customer Class

Example Class: Define Data Elements

Last NameFirst NameAddressPhoneFaxWeb Site

Customer Class

Example Class: Define Actions

Last NameFirst NameAddressPhoneFaxWeb SiteCallViewSendActionComplete

Customer Class

Example Class: Define Default Interface

Last NameFirst NameAddressPhoneFaxWeb SiteCall ViewSendActionComplete

Customer Class

DefaultInterface

Incoming

Outgoing

Example Class: Instantiate Object from Class

Customer Object 1Last NameFirst NameAddress...

DefaultInterface

Incoming

Outgoing

Customer Object 2Last NameFirst NameAddress...

DefaultInterface

Incoming

Outgoing

m_Customer1

m_MyCustomer

m_Customer2

You can have multiple pointers referencing the same object.

Example Class: Create a Collection of Objects

Customer Object 1Last NameFirst NameAddress...

DefaultInterface

Incoming

Outgoing

Customer Object 2Last NameFirst NameAddress...

DefaultInterface

Incoming

Outgoing

m_Customer1

m_MyCustomer

m_Customer2

You can have multiple pointers referencing the same object.

m_colCustomers

Class Hierarchy

Employee

InstructorIntern

Class

Subclass

The Intern is a subclass of Employee and inherits all of the behaviors and properties of Employee.

Objects as Containers

Objects can be composed of other objects.

Employees

Intern Albert Intern Bob Intern Sue Intern Ann

1/8/99 Timesheet

1/15/99 Timesheet

1/22/99 Timesheet

1/29/99 Timesheet

Collection of Employee

Collection of Timesheet

Terminology

Class - a unit of source code with one or many interfaces. Some of these interfaces may be specified as public for external use.

Object - a run-time instantiation of a class that is packaged within a component.

Properties - data that the class maintains internally. These may be visible for external use (either setting or viewing) or private for use inside the class.

Terminology Fields – Similar to properties – but you

can’t control how the user accesses the data.

Methods - The actions that are defined for an object. The default events that are part of a VB object are New and Finalize.

• New is run when an object is instantiated from the base class.

• Finalize is run prior to releasing the objects memory back to the system.

Terminology

Event - A message, broadcast from within an object.

Interface - The list of properties and methods available for external use. An object may have more than one interface.

Collection - A set of pointers to related objects.