SDD half-yearly Flashcards
(32 cards)
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.
System defintion
comprises of hardware, software, and people interacting with it
Structured programming
Describes any programming when functionality is divided into units (block structures) including for loops, while loops, if … then and so on. These units (functions) can be re-used.
Modular programming
Refers to when chunks of code are created to form packages that are general purpose and re-usable. These modules can then be compiled together.
Describe what a data flow diagram is and what it does.
A data flow diagram (DFD) is a visual representation of the information flow through a process or system, including processes, external entities and data stores.
advantages and disadvantages of a structure chart.
Advantages of a structure chart:
Hierarchy of modules
Indicates whether a module is called based on a condition being true as well as whether it is repeatedly called
Illustrates the data required to call a module
Illustrates the return values from a module
Disadvantages of a structure chart:
Too much information can cause clutter
Harder to understand the flow compared to simple hierarchy charts
Takes longer to design
Describe what a class diagram is and what it does.
It is an abstraction of a class illustrating its attributes and methods, data types of attributes, method signatures(headers), parameters expected and return types of the method, in addition it also identifies whether an attribute or a method is private or public.
Method signatures meaning
first message headers of a method - you know how the method needs to be called without needing the finer details - reduces the time of checking the values that need to be parsed
Task definition definition
A task definition, sometimes referred to as a problem statement, is a short, clear explanation of an issue or challenge that sums up what you want to change.
Top-down and bottom-up
In programming, a top-down approach, also referred to as stepwise design, is a complex algorithm broken down into smaller units referred to as modules.
Bottom-up approach entails designing an algorithm by starting at the very basic level and building it up towards the complex level. In the approach the modules are designed independently and are then integrated together to form a complete algorithmic design.