You are on page 1of 3

object

classes & objects interaction


ABSTRACTION

ignore details of parts to focus


on a higher level a
of problem
MODULARISATION

dividing whole into well-defined parts


4 can be built examined separately

DEBUG GER OBJECT INTERACTION


·

set breakpoints external method calls -

-step through code object. methodName (parameter)


-examine variables
internal method calls -

useful for gaining variable name needed


-no
insights into program
behaviour private visibility
4 Whether, nott here
is a program error preventingto becalledfromone

ja
grouping objects
class libraries:library useful
of classes

necessary
COLLECTIONS

specify: ↓it's capacity as


type collection) -
keeps private count via size()
type (objects) -

keeps objects in order

private ArrayList, string files;

4CCS1PPA
for each 100p selective processing

programming
practice &
application

/ 1
iterating over
collections
FOR EACH LOOP WHILE LOOP

L
a processing every element
While (loop condition)
a guaranteed to STOP
WHILE LOOD
↑>
may stop halfway through
loop body
-> use for repetition thatdoesn't
ITERATOR OBJECTS
involve a collection
collections
havean iterator()
-> could create an infinite Loop method

HERATOROBJECTaythrocele returns an iterator object


IteratorcE>: ⑥
sophisticated
indexed access e fficient
not
-> used to boolean has Next
remove from a collection
- neXt 1)
2
void removes
SEARCHING
CONTINUIN G
-
need to state
- Loop's
for finishing
condition for
condition:opposite
continuing
t hat
of
IMPORTING
behaviour
FINISHING WRITING
-
no more items to check, or
-
item found DOCUMENTATION
CLASS VARIABLES
=

SET CLASS CHASH SET)


·
shared between all instances
of class
CLASSESEsme
comment coverall purposes
4 belongs to class exists
+characteristics
independento f any instance
versionnumber
·
no access instance fields WC
author's name
I

can't call instance methods WC


accessed via class, variable
documentation
set class keep in specific order
-

constructors methods
+
duplicates ·public static' (variable) name (method)
return type
HASHMAP
key: value parameter names types
CONSTANTS
descriptions of:
~
fixed value once set ·

purposel function
-

'final -

each parameter
~to be set in declaration -
value returned
I constructor
INFO HIDING
WRAPPER CLASS
public elements:accessible
·
primitive types:immutable to objects in other classes
-> be
can't changed post-creation private elements:accessible
only to objects of same class
·
↓ independence

↳ important
f or large systems
~

wrapping unwrapping: + maintenance


autoboxing unboxing +

a java compiler will automatically

create a wrapper object


class design
links between
COUPLING

2 units (program) ENUMERATED TYPES


fixed-size
collections
LOOSE COUPLING TIGHT COUPLING I -
use enum instead of class
~understand 1 class x changes to ICLASS = to introduce a type name
who reading others lots of changes to others -

use:to define of
a set

~change I class w/ little


x classes harder to understand significantn ames
I no effect other classes in isolation
on alternative to static int constants
-
STANDARD ARRAYS[] FEATURES OF ARRAYS
x flow c ontrol
of between objects
~ increases maintainability of different classes:c omplex When constants' value:arbitrary
~
-

fixed in length
BASIC ENUM TYDE ·use a special syntax
A B A
B C D -
each name represents an object
-
objects w/ no methods
x provided by other classes
t he enum
of type
COUPLING:
↓ ·

array syntax supports


IMPLICIT COUPLING -

enum objects Icreated directly


encapsulation definitions:fields, multiple dimensions
linkage not necessarily expressed -
enum
-> private elements Ireferenced via data method interactions constructors, methods
from outside class FOR LOOPS-FOR-EACH +FOR
-impact (internal changes) satisfactory resolution may need

in explicit
coupling
responsibility-driven design -> a
classes/methods linked via

each class to be responsible java statements
manipulating its own data
for
-> class
↳> compiler picks up on coupling error
owning data:responsible
ARRAY LITERALS
for
processing it

y
COHESION

num-diversity oft asks a single unit:responsible for ARRAY ITERATION


HIGH COMESION LOW COHESION:
easier to: m ethods:
x multiple tasks MULTIPLE DIMENSION
~understand whata
entities
class/method does Yclasses modellingmultiple ARRAYS

~use descriptive names for


variables/methods/classes modules/packages u nrelated
of classes

~reuse classes/methods UNIT A


task one
UNIT A UIA ITERATOR:
t9SK tWO
task one ta5K three

CODE
Q UALITY

W
CODE DUPLICATION I
·

maintenance harder

-

inconsistencies terrors -
THINKINGAHEen A

4CCS1PPA
changes easier
REFACIORING
classes/methods to be
refactored to maintain
cohesion+ low coupling

programming
-
test before/after refactoring
to ensure nothing:b roken

DESIGNGUIDELINE, I logical asthe

-class:4 complex
i f represents: I
logical entity

practice &

&
application

S
streams &
lambdas ↓
LAMBDA
SYNTAX

testing & test-


LAMBD AS

METHODS US LAMBDAS
TYPES (ERRORS)
-

no visibility keyword

automation
syntax errors
-

no return
-

type
-
no name slist (parameters) ->
↳ early errors

ampiler
->

spotted by
separates parameters (statements to executed) -

logic errors
from body
STREAMS
↳ later
errors ↑CHANCESCDETECTION) NLIKELIHOOD CERRORS(

L
-> not
s potted
SYNTAX VARIATIONS -use SE practices Use SE techniques
-

(similar to collections)
leave out parameter - modularisation + good encapsulation
->
type
-
Leave out brackets
-accessed sequentially TESTING+ DEBUGGING
documentation
pay attention to
-

IfI parameter/statement
~
-contents I changed test:presence (errors) cohesion/coupling
write in one line Stream can be infinite JUNIT
debug:s ource cerrors)
-
-

~shorter errors COLLECTIONS - STREAMS


TESTINGFUNDAMENTshould test cases:m ethods wl tests
-

~ Treadable - possible concurrency test classes contain test methodi s


do -

positive/negative tests -assertions:assert expected


test boundaries
FILTER/MAP/REDUCE
methodresultof multiple tests
-

blackbox + whitebox
- .

FILTER PIPELINING
bb:tests functionality
&

select some elements


(combines streams)
-
↳ wb:uses source code to
-create new stream we examples: determine test cases
selected elements
-some elements filtered out TEXT FIXTURES
METHOD REFERENCES::
MAP set (objects) in predetermined
INTERMEDIATE TERMINAL
-original stream mapped -
x Math.abs(x) (stream)
->

state used to run 1/+ tests


to a new stream
OPERATIONS
last operation:terminal, all math::abs
4
annotations:
-
each elementreplaced Strt
others:i ntermediate system. out printin (str) (stream)
by a differento ne ↳ System. Out ::printin TEST HARNESS
-
derived from original -
Str-> str. length (
REDUCE ↳ String::length -extra classes written to
-collapse stream into
single result
a
intermediateoperationsre -

new
-

Array list ( automate testing


must be updated as functionality
ArrayList::new
-


-terminal operations produce is added
a result or void
STREAMS + LAMBDAS TEST DRIVEN
MAP (Intermediate) DEVELOPMENT (TDD)
FILTER (intermediate( -

takes Lambda which recieves


-

passes elements which fulfil element + returns new element tests serve as spec's
condition to outputs tream (terminal
REDUCE
when defect reported,
-If boolean Lambda (predicate) true, write a test - make it
p ass

Faccutationarementor
=

element passed to output


s tream Stream
-for eachterminal Start ↓
value for for final result
final result
&firstac/
parameter

removal from collection


inheritance
ALLOWS DEFINITION OFC LASSES AS
graphical user
interfaces
EXTENTIONS OF OTHER CLASSES SUPER STAGE (WINDOW(
overrides

ADVANTAGES
a
methods/ ↑
STACKDANE?"BOOT"(

S
~
attributes
SUB TITLE
~ avoids code duplication POLYMORPHISM instance of

(GUIs)
~allows code reuse
can hold objects of more TYPES determines
~ simplifies code LABEL
than one type runtime
dynamic type
~ simplifies maintenance t DYNAMIC:occurs at

whensomething's been
store the

~handranabitthe CASTING BUTTON


SETUP (BASIC)
-
can assign subtype to STATCexplacatdefinitionofcase ingaragee

SUPER CALL supertype but notVV. BUTTON CLICK ACTION EVENT
a piece of data error-free)
-

object:u nchanged
runtime check to ensure object
subclassconstructosein SCENECWINDOW CONTENTS
-
-

is of that
t ype PROTECTED ACCESS
ADDING MENUS
↳ class cast Exception public, protected private
↳ Supercauthor); 5 AUAFX PANES
-

superclass:private
if none written, compiler
↳ subclasses:p rotected BORDERDANE, MBOX,
.

inserts one who param


STACKPANE, GRIDDANE,
↳ only compiles if superclass
FLOWDANE, TILEPANE,
has a constructor who param

-calling superclass' methods: SYNE


EVENT HANDLING
super method (...);
WARARGS USER INTERACTIONS WICOMPONENTS

&
M
method takes multiple
arguments oft he same type
METHOD CALL METHOD REFERENCE

S
DIALOGS

ALL THING IMAGES

LABEL
IMAGE won OPAbasalenteracticactions

coding bits
LOAD IMAGE FILTERS

TYPES:INFORMATION, WARNING, ERROR,


SHORTCUT EVALUATION ORDER OF
EVALUATION
TEXT INDUT, CONFIRMATION, CHOICE

Lunary, binary) operators

CASTING+COERCION BUTTONS
INCREMENT OPERATORS
BOSTFIX PREFIX

INTEGER TYPES FLOATING POINT

4CCS1PPA
TYDES
BYTE (8 BITS(
FLO AT
SHORT (16 BITS)
INTC32 BITS) DOUBLECDEFAULT
OBJECT EQUALITY
LONG C64 BITS)
REFERENCE EQUALITY
( =
=
3 VISUAL EFFECTS
ISTRING) CONTENTE QUALITY TRANSITIONS

programming
EG.DROPSHADOW, LIGHTING,

REFLECTION
1.2q4a1S())
EG. FADE, SCALE, TRANSLATE

practice & & SCENEBUILDER

recursion application
MODEL/VIEW/CONTROLLER (MUC(

MODEL:core (app functionality)

ISE
VIEW:visible interface
ARECURSIVE FUNCTION CALLS CONTROLLER:Managing user interaction
INDUT ~ separation (concerns) - reusability

TWOTBinte

#
7 -
CALLONE CALL ~ cohesion ~ Loose coupling
OUTPUT -

css styling
DEFINE NEW STYLE CLASSES
STYLE
S HEETS

handling errors COMPOUND SELECTORS

THROW EXCEPTION CATEGORIES PSEVDO CLASSES ID SELECTORS

CHECKED node in specific state

for anticipated failures


where recovery possible
UNCHECKED
ARGUMENT CHECKING
for unanticipated failures
where recovery unlikely

↳ possible termination
·FINALLY CLAUSE
TRY'STATEMENT
executes regardless of
Whether an exception occurs

PREVENTING OBJECTCREATION

MULTIPLE EXCEPTIONS
file-based I/O
OPEN/WRITE F ILE
TO ICLOSE
>IOEXCEPTIONS
DEFINE NEW EXCEPTIONS
TO FILE
WRITE

READERS,WRITERSSTREAMOSene
Input (char) data (byte)

CHARACTER SETS

charset decodes bytes into characters

ASSERTIONS
ENSURERESOURCEOSE
D

testing correctness of
assumptions made in program

can-RRORAVOAng
( EXCEPTIONS)
:ALTERNATIVE SCANNER
USE FOR INTERNAL CHECKS
supports parsing of
textual input
Emorecovery

You might also like