D.1 Objects as Programming Concepts

studied byStudied by 3 people
0.0(0)
Get a hint
Hint

Object

1 / 27

28 Terms

1

Object

  • representation of a real world entity (book, car, student, etc)

  • When designing a new system identify all objects that you need to deal with (student, parent, alumni, donation, etc)

OR

  • a particular instance of a class where the object can be a combination of variables or data structures and functions, procedure, or methods.

New cards
2

Class

  • a template for creating the objects. It identifies what data needs to be stored (in fields) for the objects of this type and what methods are available to allow access to this data

    • Constructor method of the class has the same name as the class.

OR

  • an extensible program-code-template for creating objects, providing initial values for states, and implementations of behaviors.

New cards
3

Instance

when the program has allocated memory to hold the object. The object exists at runtime (instantiation).

New cards
4

What happens to an object when executing a program?

When executing a program the object takes on a different meaning, an object is created by a constructor of the class, and the resulting object is an instance of the class.

New cards
5

Three steps to making an object

  • Declaration: a variable declaration with a variable name with an object type.

  • Instantiation: the ‘new’ keyword is used to create the object.

  • Initialization: the ‘new’ keyword is followed by a call to a constructor, this call initializes the new object.

New cards
6

Example of an object being instantiated (Car is the class)

Car polo = new Car (“VW Polo 1.4”)

New cards
7

Instantiating objects and RAM

  • Instantiating objects uses RAM

  • Every time a new object is instantiated from a base class a space equivalent to the whole object is reserved in RAM

    RAM can be wasted as it is reserved but not used

  • Use the most memory efficient variables

New cards
8

How to save memory with objects

  • Creating a linked list (dynamic data type) of objects is good because only memory actually being used is reserved.

  • It is bad to create an array (static data type) of objects because potential memory could be wasted in reserving space that might not be needed.

New cards
9

Components of an object

  • Data (or states) are variables or data structures like arrays/lists

  • Actions (or behaviour) which can be methods

New cards
10

Objects versus classes

  • Object - refers to a particular instance of a class, where the object can be a combination of variables or data structures (called states) and functions, procedures, or methods (behaviors).

  • Class - an extensible program-code-template for creating objects, providing initial values for states (variables) and implementations of behaviors.

New cards
11

Example of an object being instantiated

Car [object template being used] polo [name for the specific instance] = new [java keyword indicating it is the first time this is being done] Car [name of the constructor method to set default values] (“VW Polo 1.4”) [value(s) being sent into the new object as default values]

Car polo = new Car(“VW Polo 1.4”)

New cards
12

UML Diagrams

  • Associations are shown with lines or arrows.

  • Shows the objects, variables, and methods.

New cards
13

Association

There are relationships such as structural links

<p>There are relationships such as structural links</p>
New cards
14

Inheritance

When one class is a subclass of another, meaning it has inherited its characteristics and can also have its own

<p>When one class is a subclass of another, meaning it has inherited its characteristics and can also have its own</p>
New cards
15

Cardinality

  • The possible number of classes that can be had in the relationship

  • For example for each user class there can be many recipes

  • Exactly one (1)

  • Zero or one (0..1)

  • Zero or more (*)

  • One or more (1…*)

  • Ordered (ordered)

New cards
16

Aggregation

  • Part of relationship

  • When class 2 is a part of class 1

  • But they still have separate lifetimes

<ul><li><p>Part of relationship</p></li><li><p>When class 2 is a part of class 1</p></li><li><p>But they still have separate lifetimes</p></li></ul>
New cards
17

Composition

  • A type of aggregation where the parts are destroyed when the whole is destroyed

  • Class 2 cannot stand by itself, it dies and lives with class 1

<ul><li><p>A type of aggregation where the parts are destroyed when the whole is destroyed</p></li><li><p>Class 2 cannot stand by itself, it dies and lives with class 1</p></li></ul>
New cards
18

Dependency

  • An object of one class might use an object of another class in the code of a method

  • If the object is not stored in any field other than this it is modeled as a dependency relationships

  • Exists between two classes - changes to the definition of one may cause changes to the other (but not vice versa)

  • Class 1 depends on class 2

<ul><li><p>An object of one class might use an object of another class in the code of a method</p></li><li><p>If the object is not stored in any field other than this it is modeled as a dependency relationships</p></li><li><p>Exists between two classes -  changes to the definition of one may cause changes to the other (but not vice versa)</p></li><li><p>Class 1 depends on class 2</p></li></ul>
New cards
19

Realization

  • A relationship between the blueprint class and the object containing the respective implementation level details

  • Eg: the owner interface might specify methods for acquiring property and disposing of property. Both the person and corporation classes implement these methods but in different ways

<ul><li><p>A relationship between the blueprint class and the object containing the respective implementation level details</p></li><li><p>Eg: the owner interface might specify methods for acquiring property and disposing of property. Both the person and corporation classes implement these methods but in different ways</p></li></ul>
New cards
20

Decomposition into Several Related Objects

  • This is turning a problem into objects.

    • Break down a larger problem into smaller solutions. If you are making a digital clock, it is made of two two digit number displays. Create a class numberDisplay and a class clockDisplay which both is made of two numberDisplay objects.

    • Breakfast is made of toast which is made of bread and jam

New cards
21

Why should dependancies be reduced between objects in a given problem?

Dependency is bad because it increases maintenance overheads. This means more change has to be made to the entire system to change one component.

New cards
22

Key Data Types

  • Integer

  • Real (double)

  • String

  • Boolean

New cards
23

Why are different types of data needed?

  • Data is stored as a combination of binary values in the computer.

  • Data types are used to store different kinds of data.

  • They are needed because they specify to the computer how to interpret the binary values in the storage.

New cards
24

How much storage does different data types take up?

  • Boolean 1 byte

  • Integer 4 bytes

  • Real 8 bytes

  • String - multiple the number of characters by two then add 38, then round up to the next multiple of 8

New cards
25

Parameters

  • Parameters allow information or instructions to be passed into functions and procedures

  • Parameters are the names of information that we want to use in a function or procedure

New cards
26

Arguments

The values passed in the parameters

New cards
27

To instantiate an action you need:

  • Return type

  • Function name

  • Parameters

Int product (int x, int y)

New cards
28

Java as a “pass by value” language

  • Pass an int to the method change() and as a result the change in the value of that int is not reflected in the main method

  • Java creates a copy of the variable being passed in the method and then does the manipulations

  • Hence the change is not reflected in the main method

<ul><li><p>Pass an int to the method change() and as a result the change in the value of that int is <em>not</em> reflected in the main method</p></li><li><p>Java creates a copy of the variable being passed in the method and then does the manipulations</p></li><li><p>Hence the change is not reflected in the main method</p></li></ul>
New cards

Explore top notes

note Note
studied byStudied by 12 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 66 people
Updated ... ago
4.2 Stars(5)
note Note
studied byStudied by 15 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 19 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 44 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 11 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 66 people
Updated ... ago
4.8 Stars(4)
note Note
studied byStudied by 260 people
Updated ... ago
4.5 Stars(4)

Explore top flashcards

flashcards Flashcard24 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard44 terms
studied byStudied by 3 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard59 terms
studied byStudied by 14 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard28 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard46 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard39 terms
studied byStudied by 21 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard32 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard23 terms
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)