Escolar Documentos
Profissional Documentos
Cultura Documentos
IPEA 4
Inherits methods & structure but can override or add new methods, and add
instance variables.
2)
Encapsulation
3)
Polymorphism
Abstraction
VOCAB
Cohesion
How well a set of elements group together, belong together how unified
their nature is, how strongly they relate to each other. Do they do/represent
one specific thing?
High cohesion is associated with robustness, reliability, reusability and
understandability. Low cohesion is associated with being hard to test, reuse,
maintain and read.
Coupling
PRINCIPLES
Focus on what the code needs to achieve, not how it does, to create a
structure/pattern that works even if the hows/implementation changes.
Implementation more likely to change than structure, and its already harder
moulding structure to fit implementation than vice versa so let
implementation depend on more reliable static structure.
Code Re-use
Blackbox framework
Importing and using classes within your own classes to add application-specific
behaviour (dont really look into their classes)
Whitebox framework
Inheriting skeletal implementation from a class then adding applicationspecific behaviour (rip their classes open and add to their insides)
Refactoring 2
- Rename method: To rename, create new method with new name but
same body, change old methods body to call new method, and
systematically change every old reference to old method, to new one.
- Moving common subclass methods to superclass: Check/make method
bodies and signatures the same via rename method & var changing.
Make superclass method and copy body over. Change reference to old
signatures to new. Test to catch all. Delete one old method, test, repeat
until error.
UML
- Long standing behaviour-info combo, look for nouns & noun phrases
describing responsibility (like product and buyer, transaction and
sender)
Relationships
Abstract classes
Interface
Design Patterns 5
The client asks the factory to make something, the factory knows how to
create what the client wants (knows which class it should be and what
constructor to call) and so does. They all inherit/implement the same abstract
class or interface so the client can interact with them the same way
ADAPTER (wrapper)
CHAIN OF RESPONSIBILITY
The client makes a request that a class takes on and if it cant handle it, hands
it to the next successive handler. This continues until it is handled.
STRATEGY
As the context changes, what strategy should be used (for some request if it
were called in this context) is associated with that object[-request combo] (e.g.
via an encapsulated var strategy that is used in the method body for the
request to call the right algorithm) so at any time, the clients request will be
automatically passed onto the right <<Strategy>> implementations method
(which are of course all invoked the same, but have different bodies)
OBSERVER
- Garbage collection even if the concrete classes are not used, they
wont be garbage collected until the observer removes its reference to it
- Problems if the list of references changes/object state changes during
notification and update process
Threads
CONCURRNCY IN JAVA
They share
They fork/join: fork off to do concurrent tasks then join main execution thread
Pros
Cons
Thread Safety
System calls or library routines are thread safe if they can be called
simultaneously by multiple threads, yet still give the same result.
LIVENESS HAZARDS 3
1) DEADLOCK
2) STARVATION
3) LIVELOCK
Take more than one step to complete thus potentially allowing interleaving
actions (not thread-safe sometines!) vs one step actions that dont.
o When one thread modifies shared data but another sees instead
stale data (not most updated)
o When an object has escaped (published when it shouldnt be)
before fully constructed
E.g. returned from non-private method
Passing to method in other class
GOLDEN RULE
If many want to access a shared (mutable) state var and even ONE wants to
modify: All access must be synchronized.
So of course STATELESS OBJECT= THREAD SAFE