OOP techniques Flashcards
standard Collection methods
.addItem(data) (adds to collection)
.resetNext (start at beg)
.hasNext (true/false)
.getNext (retrieves next data item)
.isEmpty (checks if collection empty)
OOP
use programming objects that have data (properties) and behavior (methods) using abstraction
inheritance
one object aquires properties of another (keyword: extends and implements)
“IS-A”
abstraction
hiding unwanted information (only necessary shown)
don’t need to understand how it works, just how to use it
encapsulation
making fields in a class private and providing access via public methods (get/setters)
- cannot be accessed outside class (data hiding) or changed
dependency
“USES-A” Relationship
aggregation
creating an instance of an object in a different class, “HAS-A”
polymorphism
subclasses of super class define own unique behaviors and yet share some same functionality as parent class –> overriding & overloading
method overriding
same method, different class (subclass) –> overriding & overloading
method overloading
different method, same class *diff parameters)
features of Unicode (internationalization)
- display of international fonts and texts
- language/local needs e.g. date/time formatting
- keyboard layouts (or complex char/symbols)
- variety of written languages
- global software deployment
+ASCII takes up less bytes per character, has more variety
problems with OOP
- increased complexity (more lines of code, and slower)
- unsuited to particular problems e.g. functional-programming style
advantages of polymorphism
- different actions but same name
- subclasses unqiue but inherit parent actions
- inherit without rewriting code and can alter the needed ones (reusability)
- extnesibility – other subclasses could be added later
advantages of modularity
- easier debugging and testing
- speedier completion
- code blocks reusable
features of OOP
APIE
Abstraction, Polymorphism, Inheritance, and Encapsulation
static modifier
variable will be the same for all instances of an object
operator
(set of) character(s) that represent an action e.g. boolean/arithmetic/assignment/relational operators
fundamental computer operations
ADD, COMPARE, RETRIEVE, STORE
need for higher level languages
- more time efficient
- less room for error
- errors more easily found
need for translation from higher level language
compiler: translator, only once (no recompilation)
interpreter: translates every time run, reads line by line
java combines both
selection sort
find the smallest element in the array and swap it into the first position, then find the second smallest and swap it into the second position, and continue with the next and next smallest until sorted (double loop)
bubble sort
simplest sorting algorithm
continuously compares adjacent elements and swaps them if the second is smaller than the first (double loop)
selection sort algorithm
- loop i from 0 to n-2
- loop j from i + 1 to n-1
- compare two vals and reassign min if needed
swap AFTER first loop
bubble sort algorithm
- loop i from 0 to n-2
- loop j from 0 to n - i - 1
*both start from same bc comparing adj - swap adjacent vals if need INSIDE inner loop