Chapter 20 Flashcards
"Further Programming"
low-level programming
programming which gives instructions directly to the computer’s hardware
used for maximum efficiency and speed. an example of low-level is assembly language
addressing modes
immediate = the value of the operand is used in the instruction (no reference to memory)
direct = the operand is the memory address which holds the value to be used
indirect = the operand is a memory address which holds another memory address where the value to be used is
indexed = the operand contains a value that must be added with the IX, to produce the address where the instruction to be executed is
relative = the operand forms the distance of the value’s instruction (combined with the PC or IX) from the address of the current instruction
symbolic and absolute addresses
symbolic addresses = contains a symbolic name for the address it represents
absolute addresses = the numeric address of a memory location. restrictive - program cannot be loaded anywhere else in memory
imperative programming
describes step by step the commands the computer should follow to complete a task in the order it was given
- is an imperative sequence of statements
- use variables which are changed using assignment statements
- use variables, loops, conditional statements
an example of this is python or java
object-oriented programming (OOP)
organizes code into objects. translates real world into code.
Python and Java are object-oriented.
advantage of OOP over imperative
produces robust, more reliable code
attributes can only be manipulated using methods from the class, protecting from accidental change.
objects
an instance of a class
create an object (pseudocode)
objectName <- NEW className(<param></param>, <param1>, ...)</param1>
class
a template for objects.
a data structure that is created by the programmer and has its own attributes and methods which operate on the class.
declare a class in OOP pseudocode
CLASS class PRIVATE attribute : DATATYPE PUBLIC PROCEDURE NEW(Givenattribute : DATATYPE) attribute <- Givenattribute ENDPROCEDURE PRIVATE attribute1 : DATATYPE attribute1 <- value PRIVATE FUNCTION GetAttribute1() RETURNS DATATYPE RETURN attribute1 ENDFUNCTION ENDCLASS
first procedure is to set the attribute, the function is to return the value of the attribute
methods and properties are assumed to public unless otherwise stated.
new and getattribute1 are just names, all of the names here can be changed
why are attributes private? are methods public?
- so that only that class has direct access to the variable - everything else needs a method to change/access the data.
- to ensure attributes can only be accessed by the class’s own methods
- to enforce encapsulation//to protect them
yes, methods are public, due to the aforementioned reasons.
properties/attributes
data stored about an object defined in a class
methods
subroutines in an object operating on the data
the procedures in a class implementing the behaviours that act on the properties/attributes
inheritance
allows a new class to inherit the properties and methods of an existing class
the child/subclass has access to all the attributes and methods of the parent/base/superclass, along with having their own attributes and methods.
inheritance in pseudocode
CLASS childClass INHERITS parentClass