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

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

Dec 14, 2015

Download

Documents

Waylon Lain
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

Object Oriented ProgrammingIntermediate VB

Doug Waterman

Fox Valley Technical College

Page 2: Object Oriented Programming Intermediate 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.

Page 3: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

Page 4: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

Page 5: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

Elements of an Object Oriented System Abstraction Encapsulation Inheritance Polymorphism

Page 6: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

Page 7: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

Page 8: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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!

Page 9: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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

Page 10: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

Page 11: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

Page 12: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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”.

Page 13: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

Example Class

Customer Class

Page 14: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

Example Class: Define Data Elements

Last NameFirst NameAddressPhoneFaxWeb Site

Customer Class

Page 15: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

Example Class: Define Actions

Last NameFirst NameAddressPhoneFaxWeb SiteCallViewSendActionComplete

Customer Class

Page 16: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

Example Class: Define Default Interface

Last NameFirst NameAddressPhoneFaxWeb SiteCall ViewSendActionComplete

Customer Class

DefaultInterface

Incoming

Outgoing

Page 17: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

Page 18: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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

Page 19: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

Class Hierarchy

Employee

InstructorIntern

Class

Subclass

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

Page 20: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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

Page 21: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

Page 22: Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.

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.

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

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.