Doug Waterman Information Technology Department Fox Valley Technical College.
Object Oriented Programming Intermediate VB Doug Waterman Fox Valley Technical College.
-
Upload
waylon-lain -
Category
Documents
-
view
219 -
download
1
Transcript of 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.
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.
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: 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.