Algorithms 1.2 Flashcards
Object-oriented programming
Based on building data types
Data type
A set of values and a set of operations on those values
Abstract data type
a data type whose internal representation is hidden form the client
Objects
an entity that can take on a data-type value
Characterization of objects (3 properties)
1) State of an object- value from its data type
2) Identity of an object distinguishes one object from another
3) behavior of an object is the effect of data-type operations
reference
a mechanism for accessing an object
API
list of constructors and instance methods
client
program that uses a data type
implementation
the code that implenets the data type specified in an API
Creating an object for a abstract data type
First, you must create an object my invoking a constructor ( new). Everytime a client uses new the system allocates memory space for the object, initializes its value and returns a reference to the object
Invoking instance methods
e.g. heads.tally () - tails.tally
Assignment Statements
A copy of a reference can be created. Leads to a situation called aliasing
Objects as arguments
Objects can be used as arguments
Objects as return values
An object can be used as a return value from a method
Arrays are objects
Every value of any nonprimitive type is an object. E.g. arrays are objects