[ 1.2.4 ]
what are programming paradigms?
different approaches to using a programming language to solve a problem
split into two broad categories (imperative/declarative) which can be broken down into more specific paradigms
what is imperative programming?
programming where the code clearly specifies the actions to be performed
what is declarative programming?
programming where the code states the desired result and the programming language determines how best to obtain the result
details about how result is obtained are abstracted from the user
what is functional programming?
a declarative paradigm
functions form the core of the program
function calls are often combined within each other
closely linked to mathematics
what is logical programming?
a declarative paradigm
a set of facts and rules based on the problem are defined
queries are used to find answers to problems
what is procedural programming?
a widely-used imperative paradigm as it can be applied to a wide range of problems
written as a sequence of instructions
easy to write and interpret
instructions are carried out in a step-by-step manner
what are the features of a procedural language?
written as a sequence of instructions
provide traditional data types and data structures
simple to implement and applicable to most problems
not possible to solve all kinds of problems or may be inefficient to do so
structured programming is a popular subsection of procedural programming in which the control flow is given by four main programming structures:
sequence, selection, iteration and recursion
what is assembly language?
low level language that is the next level up from machine code
uses mnemonics, which are abbreviations for machine code instructions
commands used are processor-specific
each line in assembly language is roughly equivalent to one line of machine code
what is the function of the LMC command ADD?
add the value at the given memory address to the value in the accumulator
what is the function of the LMC command SUB?
subtract the value at the given memory address from the value in the accumulator
what is the function of the LMC command STA?
store the value in the accumulator at the given memory address
what is the function of the LMC command LDA?
load the value at the given memory address into the accumulator
what is the function of the LMC command INP?
allows the user to input a value which will be held in the accumulator
what is the function of the LMC command OUT?
prints the value currently held in the accumulator
what is the function of the LMC command DAT?
creates a flag with a label at which data is stored
what is the function of the LMC command BRZ?
branches to a given address if the value in the accumulator is zero (conditional branch)
what is the function of the LMC command BRP?
branches to a given address if the value in the accumulator is positive (conditional branch)
what is the function of the LMC command BRA?
branches to a given address no matter the value in the accumulator (unconditional branch)
name the two parts of a machine code instruction.
opcode and operand
what is the opcode?
the part of an instruction that specifies the instruction to be performed and the addressing mode
what is the operand?
the part of an instruction that holds a value related to the data on which the instruction is to be performed
what does an addressing mode specify?
specifies how the operand should be interpreted
what is immediate addressing?
the operand is the actual value upon which the instruction is to be performed
what is direct addressing?
the operand gives the address which holds the value upon which the instruction is to be performed
what is indirect addressing?
the operand gives the address of a register which holds another address, where the data is located
what is indexed addressing?
an index register is used, which stores a certain value. the address of the data is determined by adding the operand to the value in the index register
what is object oriented programming?
an imperative paradigm based on objects formed from classes which have attributes and methods
suited to problems which can be broken into reusable components with similar characteristics
focuses on making programs that are reusable and easy to update and maintain
what is a class?
a template for an object that defines the state and behaviour of an object
classes can be used to create objects by a process called instantiation
what is an object?
a particular instance of a class
what is a setter?
a method that sets the value of a particular attribute
what is a getter?
a method which retrieves the value of a given attribute
what is inheritance?
the process in which a subclass inherits all of the methods and attributes of the superclass
subclass can also have its own additional properties
what is a superclass?
a class from which many subclasses can be created
the subclasses inherit the methods and attributes of a superclass through inheritance
what is a subclass?
a class that is derived from a superclass
it can have new functionality, such as new attributes or methods
it inherits the methods and attributes of a superclass through inheritance
what is polymorphism?
an attribute of object oriented programming that enables objects to behave differently depending on their class
what is overloading?
a form of polymorphism
the methods are distinguished by passing in different parameters (different frequency or data type) into a method
what is overriding?
a form of polymorphism
the method is redefined in the subclass so that it functions differently and produces a different output (but has the same name and parameters as the method in the superclass)
if the function is called within the superclass it will function as it was initially defined
what is encapsulation?
used to hide the values or internal state of an object, preventing direct access from unauthorised parties
encapsulated attributes of an object should only be accessible/changeable by the public methods provided
why do programmers use encapsulation?
it keeps data related to an object safe so it can't be accidentally altered elsewhere in the code
what are the benefits of using object oriented programming?
high level of reusability
code made more reliable through encapsulation
makes code easy to maintain and update
classes can be reused as a black box which saves time and effort
what are the drawbacks of using object oriented programming?
requires an alternative style of thinking
not suited to all types of problems
generally unsuitable for smaller problems