Explain advanced mechanisms and techniques Flashcards

1
Q

Mutability and immutability

A

Mutable (Object)
A mutable object can be changed after it’s created.

Immutable (Object)
An immutable object can’t be changed after creation.
That said, if you’re defining your own class, you can make its objects immutable by making all fields final and private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Refactoring

A

Process used during the development/service-life of code to improve code (i.e make it cleaner, simpler, more maintainable, etc). It is often used in order to make the code better adhere to the design principles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Threads and thread safety (*)

A
Threads
Each activity is described as an instance of a thread class (only when referring to programs which have multiple activities at once). For example in Java, one specifies for each class if it is of its own thread. 

Thread safety
Computer programming concept applicable to multi-threaded code. Thread safety means that multiple threads can be executed simultaneously without any undesirable behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Defensive copying

A

A technique where an identical, but disconnected, copy of an object (including arrays) is returned instead of the original one. Thus any modification to the returned object will not affect the original object, reducing the chance of bugs since objects can be, at creation, made immutable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Mutate-by-copy

A

Instead of changing an object’s properties, create a copy of the object with the new properties, and return that instead. The original object remains unchanged, and all references to that object cannot be changed by alias updates.
N.B this is applicable when one wishes to change the properties of the object for a single instance, but not for all instances of said object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Immutable Adapter

A

If the object we want to depend on internally is mutable, but cannot (easily) be copied (i.e. defensive copying doesn’t work), we can apply a form of the Adapter Pattern to make it appear as if it were immutable. This is achieved by making an adapter-class which delegates only the “safe” methods (methods which do not mutate the object) from the mutable objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Exceptions

A

An exception (or exceptional event) is a problem that arises during the execution of a program (for example if one attempts to divide by 0). When an Exception occurs the normal flow of the program is disrupted and the program/application terminates abnormally. Since this “crashes” the program, these exceptions need to be caught (for example using a try/catch).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly