Unit 5.1 Flashcards
An object is
An object is an abstract data type created by a developer. object id an instance of a class that has states and behavior .
An object is an instance of a class that has two components, data (also called states) and actions (also called behaviors. Data can be variables or data structures such as arrays/lists and . While actions are methods
Class
A class is Blueprint of an object which shows all the functions and data that are provided by an object of a specific class.
a class is a blueprint for creating objects (a particular data structure), providing initial values for state (member variables or attributes), and implementations of behavior (member functions or methods).
Instanation
Is the creation of the object, so when you call the consturor
Obkect vs class
Object vs Class *
*
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 (called behaviours)
Class – an extensible program-code-template for creating objects, providing initial values for states (variables) and implementations of behaviours (functions/procedures/methods
intialization Vs Declaration vs Instanation
3 steps in creating an obejct from class
First declare, then instnatie then initialize
Declaration: A variable declaration with a variable name with an object type.
– Instantiation: The ‘new’ key word is used to create the object.
Intialization: the new keyword is followed by a call to a constructor
UML Diagram
First row: Class name
Second row: Variables
Third: Methods
- sign for Private
+ sign for public
# Sign for protected
Example class name dog, variables private string name . public GetString () method which is a string
Dog. (ClassName)
-Name : String (Variable is private, and type is string)
+getBreed() : String (Public method has a return type of String)
Now if you have something inside the parameters lets say you have a parameter String Name. so public GetBreed (String name )
in UML it would be
+ GetBreed (Name : String) : String (Second string represents return type)
One last recap:
3 rows for UML: First Class name, second variables, third methods
+ = Public, - Private
+Age: Int, means that this is a public int age variable
Note: Arrays go in variable row: so it would be
example
private String [] sarray;
UML row 2 (variable)
-Sarray : String []
Decomposiiton
involves breaking down a complex problem or system into smaller parts that are more manageable and easier to understand
4 types of realationships between Objects
Dependency -Uses
Aggregation - Has a
Inheritance - is a
Association - Uses
Association refers to a relationship between two classes, where one class uses or depends on the other class.
Aggregation is a “has a” realitonship in which two classes assoicate through the use of objects from the other class
Dependency refers to when onw element depends on another element
Example An object from the player class is dependent (Or “Uses”) an object of Ball Class
Association: (2 types, Aggregreation and composition
Refers to when two separate classes which establishes through their objects
Composition is a restricted form of Aggregation in which two entities are highly dependent on each other.
It represents part-of relationship.
In composition, both entities are dependent on each other.
When there is a composition between two entities, the composed object cannot exist without the other entity.
Inherintece is the mechanism by which one class inherits the features (states and behaviors) of another class.
Super class: The class whos features are inherited is known as super class
Sub class: (child class) the class that inherits the other class is known as child class or sub class
Dependency , why is it bad?
*
It increases maintenance overheads
Maintenance overheads refer to the changes that need to be made to the entire system if you make a change to a component.
For example if you change, B, it affects how C, D and E works, implying that you have to spend time fixing them to work with the “new” B.
Four key data types
nteger (Java: int), e.g. 3, -4, 999, 23
real (Java: double), e.g. -3.1415, 9.999 String (Java: String) e.g. “strange” Boolean (Java: boolean) e.g. true / false
Paramters: Arguments
Parameters allow us to pass information or instructions into functions and procedures.
Parameters are the names of the information that we want to use in a function or procedure.
The values passed in are called arguments.
Example of parameter
Public void sum (int x, int y)
Example of argument
b.sum(10,20) (((Using the method we provided values)
Paramters: Arguments
Parameters allow us to pass information or instructions into functions and procedures.
Parameters are the names of the information that we want to use in a function or procedure.
The values passed in are called arguments.
Example of parameter
Public void sum (int x, int y)
Example of argument
b.sum(10,20) (((Using the method we provided values)
Paramters: Arguments
Parameters allow us to pass information or instructions into functions and procedures.
Parameters are the names of the information that we want to use in a function or procedure.
The values passed in are called arguments.
Example of parameter
Public void sum (int x, int y)
Example of argument
b.sum(10,20) (((Using the method we provided values)