Module definitions Flashcards
What is an OO language
A language which promotes or allows object oriented programming and design
What is an object?
A collection of data
What is a class?
Defines what an object can do
What is a class method?
A static method which is associated with a class
What is an instance method?
A non-static method which is associated with an object
What is aggregation?
An object within an object where the inner object has a lifetime of its own
What is the symbol for aggregation in a class diagram?
An empty diamond
What is composition?
An object within object where the inner object lasts as long as the outer object
What is the symbol for composition in class diagram?
A black filled in diamond
What is abstraction?
Hides the implementation from the user for simplicity
What is an abstract method?
A method without implementation (no {}) - these are placeholders for sub-classes to implement/override
What is an abstract class?
A class with at least one abstract method- CANNOT create instances of the class (only references)
What is an interface?
A class where every method is abstract and any data is static and final. (a class with no implementation)
What is inheritance?
A class is as specialisation of another class
What is the symbol for inheritance in a class diagram?
A white arrow
How does inheritance work with classes?
A class extends a class
How does inheritance work with a class and an interfaces?
A class implements an interface
How does inheritance work with interfaces?
An interface extends an interface
How does inheritance work with interfaces and classes?
DOESNT WORK THIS WAY -> a class can implement an interface not the other way round
What is parametric polymorphism?
Code which works with multiple different types
What is type erasure?
Type exists only at compile time and are erased before runtime
What is ad-hoc polymorphism
Function overloading -> same function name but multiple different versions depending on the parameter types
What is sub-type polymorphism?
Sub-classing (polymorphism in OO terms)
What is runtime polymorphism?
Compiler does not know the type but looks it up at runtime
What does it mean if a variable is final?
It is unchangeable (cant be changed in any implementations or extensions, both methods and classes can be final -can’t change implementation or can’t subclass)
What is a design pattern?
A reusable solution to commonly faced problems
What is a model-view-controller?
Separates data storage, presentation to user and control logic
What is a behavioural pattern?
Patterns that change the behaviour of an object
What is a strategy pattern?
Lets another object modify the behaviour of an object
What is an example of a strategy pattern?
Layout manager
What is an observer pattern?
Tell me when something happens
What is an example of an observer pattern?
Button
What is an iterative pattern?
Lets you iterate through contents
What is an example of an iterative pattern?
For each loop! Mainclass implements class iterable, now we can have a myIterator class which implements iterator
What is an iterable?
A container to iterate through
What is an iterator?
Object to do the iteration
What is a creational pattern?
Pattern related to the creation of objects
What is a singleton?
Creates just one instance of an object and use it anywhere
What is an example of a singleton
To create a constant object
What is a simple factory?
Creates lots of instances of object
What is boxing?
Wrapping up a data type in an object
What is unboxing?
Extracting the data type again after boxing it up
What is auto-boxing?
The process of wrapping a data type in an object then extracting the data type again
What is an anonymous class?
An inner class without a name
What is a lambda?
A simpler case for an anonymous class. When an inner class without a name implements an interface with one method
What is a constructor?
Methods which are called to initialise new objects -> same name as the class like public main()
What is encapsulation?
Grouping together methods and data in a class
Who can view a public method?
Anyone
Who can view a protected method?
Anything in this package and subclasses
Who can view a package method?
Anything in this package
Who can view a private method?
Only this class can access it
What are the limitations of parametric polymorphism?
- Type erasure
- Can only parametrise on a sub-class of a specific type
How do we change something from type a to a generic type?
- Replace all of the data type with OBJECT
- Except when we are having a parameter of type T
- If a method returns a type T, type cast it before returning
What are the two types of pattern we have?
- Behavioural patterns
- Creational patterns
Give examples of behavioural patterns
Observer, Strategy and Iterator
Give examples of creational strategy patterns
Singleton and simple factory
Why are design patterns useful in general?
- Simplify coding process
- Enhance code maintainability
- Promote code reuse