D.1 Objects as Programming Concepts

studied byStudied by 3 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

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
There are relationships such as structural links
New cards
14
Inheritance
When one class is a subclass of another, meaning it has inherited its characteristics and can also have its own
When one class is a subclass of another, meaning it has inherited its characteristics and can also have its own
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 344 people
752 days ago
5.0(2)
note Note
studied byStudied by 5 people
815 days ago
5.0(1)
note Note
studied byStudied by 138 people
970 days ago
5.0(1)
note Note
studied byStudied by 16 people
691 days ago
5.0(2)
note Note
studied byStudied by 35 people
861 days ago
5.0(1)
note Note
studied byStudied by 16 people
720 days ago
5.0(1)
note Note
studied byStudied by 31 people
521 days ago
5.0(1)
note Note
studied byStudied by 15 people
741 days ago
5.0(2)

Explore top flashcards

flashcards Flashcard (33)
studied byStudied by 9 people
757 days ago
5.0(1)
flashcards Flashcard (20)
studied byStudied by 4 people
543 days ago
5.0(3)
flashcards Flashcard (22)
studied byStudied by 57 people
708 days ago
4.5(2)
flashcards Flashcard (50)
studied byStudied by 5 people
554 days ago
5.0(1)
flashcards Flashcard (42)
studied byStudied by 12 people
485 days ago
5.0(1)
flashcards Flashcard (33)
studied byStudied by 1 person
694 days ago
5.0(1)
flashcards Flashcard (31)
studied byStudied by 23 people
780 days ago
5.0(1)
flashcards Flashcard (54)
studied byStudied by 18568 people
709 days ago
4.5(362)
robot