An Introduction to Object Oriented Programming
|
Prof. David Bernstein
James Madison University
|
|
Computer Science Department
|
bernstdh@jmu.edu
|
Object Oriented Programming
- Use a responsibility-driven approach
- Start by thinking about things and the way they
are used
- Describe things in terms of their responsibilities
- Focus on understanding real-world concepts
- A car carries people and things between locations
- A music system organizes and plays songs
- Think about data and processes together
The OOP Community
- A Warning:
- Some people/textbooks "lump" various concepts together in order
to simplify the discussion
- Some people/textbooks) "lump" concepts together
becuase they actually do not understand
the differences/distinctions/subtleties
- What About JMU?
- The faculty at JMU (generally) agree on what these concepts
mean and how they should be used
- You should feel free to disagree with the JMU
"school of thought" if you can argue your case well
- While you are here, you should follow the JMU
"school of thought" (especially on graded assignments)
Key Concepts: Classes and Objects
-
Class:
- A definition of a set written in terms of the characteristics
of the elements (rather than by listing the elements)
-
Object:
- A particular element (or instance) of the set
Key Concepts: Encapsulation
- The Concept:
-
The process of combining the attributes and
behaviors/activities/functionalities of an entity in
a program unit
- The History:
- In the "early days", this wasn't done at all.
- Abstract Data Types (ADTs) popularized this idea
Key Concepts: Abstraction
- The Concept:
-
Focusing on the important characteristics for the problem/question at
hand and ignore other characteristics
- A Car Class for a Parking Application:
- A Car Class for an Ordering Application:
Key Concepts: Information/Data Hiding
- The Concept:
-
Hide the internal details of a component from all
other components
- Consider a
Weight
Class:
-
If we were to give a
Weight
class to someone
they could use it improperly (e.g., assign negative values
to ounces or pounds; assign 16 or greater to ounces)
- A Related Term:
- An Application Programmer's Interface (API)
is the visible/accessible portion of a class
Key Concepts: Characteristics of Classes
- A Reminder:
-
A class is a definition of a set using the characteristics
of the elements
- What About Characteristics of the Set?
- Example: The jackpot for progressive slot machines
- They are often called static characteristics
Final Thoughts
- Where We Are:
- We've discussed some of the concepts and principles that
define the OOP paradigm
- What's Left?
- Inheritance
- Polymorphism
- Interfaces
- Abstract Classes
- Packaging
There's Always More to Learn