SDD half-yearly Flashcards
Main OOP concepts:
Inheritance
Polymorphism
Encapsulation
Superclass and Subclass
What is instantiation?
The process of creating an object from a class is called instantiation. Attributes get allocated for that class.
What is generalisation
Extracting the essential characteristics from 2 or more subclasses and combining them under one base class
Explain why using the OOP paradigm is appropriate for developing this
software. In your response, refer to relevant OOP concepts.
- Inheritance: There is a superclass called __ with subclasses for each __. Many attributes and methods common to each subclass are inherited from the superclass. Polymorphism: Each instance of a subclass behaves slightly differently to the same input. For example, a dog will react differently to a command given by its owner and by a stranger.
These concepts make OOP appropriate as there will not be a need to write code defining the attributes and methods of each subclass.
In addition, it gives the programmer the scope to have similar methods react differently to the same input.
Describe abstraction in the context of object-oriented programming
Hides the complexity and finer details of a class/object, to allow for convenient usage and maintenance. E.g. class signature - print() function in python allows you to use function without needing to know the inner details of the function
With reference to the fragment of code above, explain the importance of
inheritance in the OOP paradigm. (3)
My answer (3 points for 3 marks):
Inheritance enables attributes of a superclass to be automatically assumed by its subclasses, thus saving the programmer from having to redefine them.
1. We do not need to re-write the common attributes and methods while modelling a WATERBIRD since it inherits from the BIRD class
2. Evolution of the program can be done easily, say by adding a new subclass for NON_FLYING_BIRD
3. We could use method overriding (a type of polymorphism) to change the behaviour of a subclass
Explain the relevance of OOP in developing the computer game
Since the computer game consists of various characters, these characters can be defined as objects. These characters or objects can be given common characteristics, and they may inherit their attributes from a parent class. These characters or objects can also interact with each other in specified ways through defined methods.
Polymorphism, specifically method overriding, can be used to dynamically change the behavior of objects based on different inputs
What is Encapsulation
Bundling of attributes and methods into a single object with the use of a class. This means data inside an object is not modified unexpectedly by external code in a completely different part of the program, written by a different programmer.used to hide components or values of an object within a class from other objects, which helps to restrict access to the object.
What is polymorphism
Polymorphism can either mean overloading or overriding depending on the scenario:
With respect to overloading, polymorphism means that the same class can have 2 different methods of the same name based on the data type parsed into the class through the parameters e.g. the + operator adds 2 ints normally, but combines them when they are 2 strings
With respect to inheritance, polymorphism is called overriding which is the changing of the behaviour of an inherited method from the parent class. i.e. a method with the same name (function signature) and same parameters acts differently when it skips the superclass method and instead goes straight to the subclass method of the same name (overriden) e.g.
Describe how polymorphism is used in the code provided. Refer to line numbers in your response. (3)
The methods on lines 3 and 8 have the same name, operator, but act differently when given different parameters. Calling the method ‘operator’ on line 16 executes different logic from calling the method ‘operator’ on line 17 as the parameters have different data types. Therefore, the processing of the method ‘operator’ changes based on the parameters provided when the method is called.
Imperative paradigm
old paradigm where data and processes are separated and the entire program is a single algorithm or has complete functionality and is written linearly, that is, step-by-step. sometimes it is used when speed and efficiency is prioritised.
Object orientated programing paradigm
Object-oriented programming is a programming paradigm based on the concept of objects, which can contain data and formed from classes: data in the form of attribute values, and code in the form of classes
What is meant by an object?
An object is an instance of a class and has specific values for its attributes. Hence two objects of the same class can have different values for its attributes, indicating its current state.
What are classes?
A template that encapsulates the methods and attributes
Describe system modelling.
System modelling - covers the manual (user-side) and mechanic (automatic/computer-side) operations as well as the computing operations of a system.