4.1 - Fundamentals of programming Flashcards
Define ‘subroutine’.
A named section of code that can be called by writing the subroutine’s name in a program statement
What are the 3 advantages of using subroutines?
Makes the code more readable and reusable - code is broken into smaller sections
Most programming languages come with a standard library of built-in subroutines to perform common functions
Pre-written libraries of code come from a reliable source - will hopefully be well-tested as they will have been used in a large number of different programs
Define ‘local variable’ and ‘global variable’.
Local variable - a variable that can only be accessed from the subroutine within which it is declared
Global variable - a variable that can be accessed from any part of a program and exist in memory for the entire duration of the program’s execution
What are 3 things that are stored using a stack frame?
Return addresses
Parameters
Local variables for each subroutine call that occurs during the execution of a program
What is a recursive subroutine and what is a base case?
Recursive subroutine - a function that calls itself until a base case is met
Base case - the condition(s) at which the subroutine is no longer called
What is the structured approach to programming? (3 points)
Designed from the top down
Most important elements of a problem are broken down into smaller tasks
Each of which can be solved in a block of code such as a procedure or module which goes on to form part of the overall solution
What are the 2 advantages of the structured approach to programming?
Makes maintaining the program easier - navigation of different elements of the overall solution is improved
Testing can be carried out on the individual modules before they are combined to form the overall solution
What is a class?
A blueprint for objects that specifies what properties (data) and methods (instructions) objects of their type will have
What is an object? (2 points)
Anything that we can name and describe
Things that we want to model within our programs - anything that exists in the real world that has some specific meaning
Define ‘instantiation’.
The process of making an object from the class definition
Define ‘encapsulation’.
The process of combining methods and procedures to form an object
Define ‘inheritance’.
Is-A - allowing one class to share the properties and methods of another class while having its own properties and methods too
Define ‘aggregation’. (2 points)
The weaker of the two kinds of association (Has-A)
The object can exist independently of the object it is associated with
Define ‘composition’.
A stronger relationship between classes (Has-A aka Part of)
The object is deleted if the object it is associated with is deleted
Define ‘polymorphism’.
Objects of different classes/types responding differently to the use of a common interface/the same usage