Object Oriented Programming Flashcards
Question 1: OOP
Selection
Conditional Statements (“if” statements)
Choices
When “if” statements hs “else” it becomes a choice
Iteration
Doing something more than once (using “for”, “do”, “while)
Structured Code
Any combination of sequence, selection, and iteration
Procedural Code
Procedures address a problem with structured code
Problems with Global Variables
Is it safe to use?
Where did the values come from?
Subroutines
Reducing duplication of code within a program
Global Variables
a variable type that is declared outside any function and is accessible to all functions throughout the program
Object-Oriented Programming
Model the world as objects.
Objects can send “messages” to each other.
Static Fields
A static field belongs to the class Do not change from one instance to the other
Static Methods
Do not need to create an object of the class in order to call the method. Can be called through the class name "Classname.staticmethod();" or "staticmethod()" if in the same class Can not be overridden Can only call other static methods Only access static fields
Class
Group of objects with similar attributes or behaviour
Final Class
A final class cannot be subclassed
Final Methods
A final method cannot be overridden or hidden by subclasses
Final Variable
Can only be initialised once
Association
Represents a general relationship that describes an activity between two classes
“uses”
if class A uses class B, then one ore more methods of class B will be invoked by class A (from one or more methods in class A).
Aggregation
Aggregation is a special type of association. That is, a class that is defined in part by another class is dependent on that class.
“has a” relationship or “made of”
Composition
An aggregation relationship that implies a child cannot exist independent of the parent.
Inheritance
“is an extension of” relationship.
Manager and secretary are extensions of employee
Inheritance vs Aggregation
A dog is an animal (inheritance) (is a)
A person cannot exist without a name (aggregation) (has a)
Polymorphism
The ability of an object to take on many forms. Often seen with a parent/child relationship between classes.
Method Overloading
a feature that allows a class to have more than one method having the same name, if their argument lists are different.