Paper 2 Flashcards
Explain the nature of an object. (3 marks)
- It is an instance of a class
- Objects will have:
1. Attributes with initial values
2. Behaviours/methods/actions
Define an object
- instance of a class
- created through INSTANTIATION
- using the ‘new’ keyword
- which calls the constructor method
- to allocate memory location for the objects’ initial attribute values
Define a class
- Template/Blueprint for creating objects
- Has private attributes and public behaviours
- Encapsulation -using the private attributes that can only be accessed within the same class
- Private attributes that can be accessed outside the class using public behaviour (accessors and mutators)
What is the code for creating an object?
className objectName = new className();
e.g:
Student Thaniish = new Student();
Define Instantiation
-Process of object creation from a class
- Uses the ‘new’ keyword which calls the constructor method
- Using the Overloaded constructor - Initialisation -> initial values to the attributes
- Using the default constructor, initialisation is done using mutators
Declaration
When a data type is assigned to a value
Instantiation
Using the ‘new’ keyword
Initialisation
When arguments are applied to an overloaded constructor.
What does Decomposition lead to?
Modularity
What is Modularity?
- Maintainability - one module does not affect another
- Readability - smaller modules ~> better organisation
- Reusability - existing modules can be reused across other modules
What is the need for decomposition?
- Simplified Debugging
- Modular
- Enhanched Reuseability
- Scalability (updates or extensions)
What are dependencies?
Relationships
What type of dependencies are there?
- Inheritance: ‘is a‘ relationship e.g class subclass extends superclass
- Aggregation: ‘has-a’ (object creation)
What are some negatives of dependencies?
- Maintenance overheads (debugging, recoding)
- Code complexity
- Difficulty in debugging
- Changes in one module requires re-coding another module (cascading impacts)
- Lack of concurrency (in inheritance superclass needs to be programmed before the subclasses)
What are the different primitive/basic reference data types?
- char
- int
- boolean
- float/double
What is the need for different data types?
- Memory efficient
- Application -> value assignment
- Specialised libraries- pre written code, pretested
What are the types of parameter passing techniques?
- pass by value ~> copy of the variable ~> memory inefficient, changes are not global
- pass by reference ~> address of the variable ~> memory efficient ~> global
What is encapsulation?
- Data Hiding/data wrapping inside a class
- Class encapsulates the attributes and behaviours
- Private attributes which can be accessed outside the class using public behaviours
- Prevents accidental modifications
What are some positives of encapsulation?
- Enchanced security
- Abstraction (hides complexity)
What are some negatives of encapsulation?
- Inefficinet for smaller projects
- Code complexity
- Over abstraction (making it too broken down leading to confusion)
What is inheritance?
- An OOP feature where a subclass extends the attributes and behaviours from a superclass
- The subclasses will inherit the common attributes and behaviours
- The subclass can have its own specific specialised attributes and behaviours
- In the subclasses, methods from the super class can be overridden for specific functionality
What are the positives of Inheritance?
- Code Reuse: saves programming time, shorter programs
- Modularity- superclass prewritten, pretested - was of debugging- maintainability
Negatives of Inheritance
- Dependency Issues
What is Polymorphism?
An OOP feature where methods with the same name perform different functions