Advanced Mechanisms & Techniques Flashcards
Mutable Object?
Object that can be changed, ex. getters and setters of objects
Immutable object?
Can’t be changed after creation. Make it immutable by making all fields final and private. for example primitive types
Refactoring?
Improving the code. For example, cleaner, simpler, better adhere to principles!
Threads?
Multiple activities at once are called Threads. Each activity is an instance of the “Thread-class”.
Thread Safety?
-Means that multiple threads can be excecuted simultaneously without any undesirable behaviors.
Defensive copying?
A identical, but disconnected, copy of an object is returned instead of the original one. Any modification of the returned object will not affect the original one. Reduces chance of bugs since objects, at creation, can be immutable
Exceptions?
Exceptions disrupts the flow of the program, and this terminates abnormally. Exceptions are caught by using “Catch”. There are checked and unchecked exceptions, what ever they are :P
Immutable Adapter?
An object that cannot easily be copied, one can apply an adapter to make it appear as if it were immutable. Achieved by making an dapater-class which delegates the methods that do not mutate the object from the mutable object
Mutate-By-Copy?
Instead of changing an object’s properties, create a copy of the object with the new properties, and return that instead. The original object cannot be changed by alias updates. Applicable when one wishes to change the properties of the object for a single instance, but not for all instances of said object.
Polymorphism?
“An object of a type can be used as if it is of a different type”
Allows an object, a method to behave as if it had several different types, i.e. its ability of an object to take on many forms. Any object that IS-A subtype of an object type is considered to be polymorphic
Subtype polymorphism?
If S is a subtype of T, then any object of type S can behave like an object of type T:
- For every subtype, “O” has a form( Scania is a Truck which is a Vehicle). Thus Scania has the behavior of a Truck and a Vehicle.
- A variable X with a static (declared) type T can at runtime point to an object with dynamic type “S” I.e. it can use any methods defined in T(or any superclass that T inherits from)
Parametric Polymorphism?
Creates a method or a class with generic code that works for whichever type the parameter is.
The code is independent of the objects type, and thus applicable to multiple different types
Delegation?
When a class (B) contains an instance of another class (C) in order to make use of C’s methods
Inheritance?
When one class gains the properties of another superclass. Attributes or methods do not all be defined in one class but can be gained from another class
Type Constructor?
A type constructor is a syntax around creating a collection of a specific type
The specified type of the collection is the type argument
Pair < T >, ”T” is the type parameter. Pair < String >, ”String” is the type argument and ”Pair” type constructor