02-object-oriented-concepts

02-object-oriented-concepts - Introduction to...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Object-Oriented Concepts CSE 114: Computer Science I 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Procedural Programming • Most older programs use a procedural methodology • Program code is divided into distinct functions or procedures • Data is stored separately, and passes through these procedures • Data may be stored globally • This means that data is uncontrolled and unpredictable — there is no way to protect data from other parts of the program Data Function 1 Function 2 Function 3 Function 4 2
Background image of page 2
What is an Object, Anyway? • So why use objects? What’s so special about objects? • Objects are a very natural way to view the world around us • Ex. People, things, even non-physical stuff (i.e., a bank account) • Objects are deFned in terms of attributes and behaviors • Attribute: properties that an object has (e.g., eye color, height, weight) • Behavior: actions that an object can perform (e.g., walk, speak, pick up) • An object is an entity that contains both data and behavior 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Objects Are Safer Than Global Data Storage • In an OO program, data is distributed among objects; there is no central “pile” of program data • An object contains all of the functions (methods, representing “behavior”) that need to operate on its data (“attributes”) • This is called encapsulation , which means that an object is responsible for managing its own data • An object may hide some of its attributes and methods from other parts of the program • This allows us to protect our data from mischief and to conceal how we represent and manipulate data inside an object 4
Background image of page 4
Data Method Method Method Method Method Hidden Methods Public Methods Data Method Method Method Public Methods Hidden Method Objects communicate with one another via their public methods 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Programming Example • Objects are the building blocks of an OO program • An OO program is a collection of objects that interact with one another • Example: Employee management software • This system needs to maintain information about company employees • Each employee will be represented by a unique object • What kinds of data should these objects store? • What kinds of behaviors should these objects provide? 6
Background image of page 6
An Employee Record • Attributes • Employee name • Employee Social Security # • Employee date of birth • Employee date of hire • Employee pay rate • Behaviors • Set/get employee name • Set/get employee SSN • Set/get employee date of birth • Set/get employee date of hire • Set/get employee pay rate 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Classes and Objects • Every object is defned by a class • IF two objects have identical behaviors and attribute types, they belong to
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 35

02-object-oriented-concepts - Introduction to...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online