Download presentation
Presentation is loading. Please wait.
Published byEdgar Jackson Modified over 9 years ago
1
Chapter 2 Data abstraction: introductory concepts
2
This chapter discusses n How to build components of a software system. n Foundational notions of value/type and object/class. n Java primitives. n Reference values.
3
Values and types n value: a fundamental pieces of information that can be manipulated in a program. n type: a set of related values along with the operations that can be performed with them.
4
Values n 2 kinds of values: u simple (atomic): integers, characters u composite: date(day, month, year), string(several characters) n Values are abstractions used to model various aspects of a problem.
5
Types n Values grouped together according to how we use them and what operations we perform on them. Example:Integers use +,-,, etc.
6
Primitives n Built-in types. Java primitives: byte, short, int, long, float, double, char, and boolean. n Java has no built-in composite primitives.
7
Numbers n Integers: byte (1 byte) short (2 bytes) int (4 bytes) long (8 bytes) n Used for counting (whole numbers).
8
Numbers (cont.) n Floating point: u float (4 bytes) u double (8 bytes) n Used to represent things we measure (anything with a decimal point). n The computer’s representation may not be exact.
9
Characters char includes upper case and lower case letters, digits, punctuation marks, and other special characters. n Characters contained in the Unicode character set. n Used for input/output.
10
Boolean Only 2 values: true or false.
11
Objects n The fundamental abstractions from which we build software systems. n Designed to support the functionality of the system. n Responsible for performing specific tasks.
12
Queries and properties n Furnish relevant information about what the object represents. n properties: characteristics about which the object provides information. n Each property has an associated value. n queries: requests for information concerning properties.
13
Commands and state n The values of properties can change at any time. n state: the set of an object’s properties and associated values at any given time.
14
Commands and state (cont.) n Commands instruct the object to perform some action which often results in the object changing state. n At any given time, a particular value is associated with each property of an object.
15
EXAMPLE SYSTEM USING OBJECTS University registration System What are the objects? StudentCourse
16
Queries: Student Course What is your name? How many credit hours? What are you enrolled in? Have you paid your fees? What is the course number? How many credit hours is it? What room is the course held in? Properties: name address ssn credit hours major year in school course number section professor room time/day total seats seats taken
17
States: StudentCourse Commands: add a course drop a course change the address determine fees change the room number set professor calculate the number of seats available
18
States and commands
19
Designing with objects n What are the objects? n What features should these objects have?
20
Particular object responsibility n What must an object know? u The properties of the entity the object is modeling, and u About other objects with which it needs to cooperate.
21
Particular object responsibility (cont.) n What must an object do? u Compute particular values. u Perform actions that modify state. u Create and initialize other objects. u Control and coordinate the activities of other objects.
22
Particular object responsibility (cont.) n Asking what an object knows: object queries. n Asking what an object does: object commands and queries.
23
Knows: StudentCourse Does(Commands): Student’s name Student’s address Student’s social security number Number of credit hours enrolled Course’s title Course’s section Course’s professor Course’s time Course’s room number Add a course to the student’s schedule Drop a course from the student’s schedule Calculate student’s fees Change room assignment Add a student to the roll Print a class roll Decide if the class is full
24
Does(Queries): StudentCourse Supplies a student’s name. Query: What is the student’s name? Supplies a student’s current classes. Supplies the student’s address Supplies the Professor of the class. Query: Who is teaching this class? Supplies the number of student’s enrolled in the class.
25
Ticket dispenser example n Queries: u How many tickets have we sold? u How many tickets are left? n Properties: u Next ticket number u Tickets left
26
Ticket dispenser example (cont.) States and Commands
27
Chess example n Queries: u Where is a certain piece? u What color is a player’s pieces? u Is a player in check? n Properties: u Player’s color u Piece’s position
28
Chess example (cont.) States
29
Chess example (cont.) n Commands: u Move a piece? u Change whose turn it is?
30
Classes n An object is an instance of a class. n A class specifies the features of a group of similar objects. n Two objects from the same class will have the same set of queries and commands, but usually contain different values.
31
Objects as properties of objects n A relation associates two or more objects in a specific, well defined way. n Relations define how objects interact to solve a problem. n An object’s property can be a reference to another object.
32
Reference Examples
33
Reference n A value that denotes an object n null reference: refers to no object.
34
We’ve covered n Introduction of fundamental notions of values and objects. n Java provides: Integer types ( byte, short, int, long ) Real or floating type ( float, double ) Character type ( char ) Boolean type ( boolean-- true/false )
35
Glossary
36
Glossary (cont.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.