procedural programming
programming paradigm where programs are formed from sequences of instructions and broken down modularly into routines and subroutines
characteristics of procedural programs
-instructions are executed in the order in which they appear
-subroutines can be called from anywhere in the program
-data is stored as variables and constants
-data structures can have a local or global scope
structured approach to program design and construction
uses assignment, sequence, selection and iteration
characteristics of the structured approach
-designed from the top down(elements are broken down into smaller tasks)
-keeps programs easy to understand and maintain as they are easier to navigate
-testing can be carried out on individual modules
-easier to develop collaboratively as each module can be assigned separately
hierarchy charts
charts representing the structure of a structured program
each procedure is diaplayed as a rectangle and connected to parent or child procedures with a line, with parent procedures above their children
object-oriented programming
programming paradigm where programs are formed from, and designed around, objects which contain their own properties and methods
OOP main principles
inheritance, encapsulation, abstraction and polymorphism
why OOP is used
-programs have a clear structure which makes developing and testing easier, as well as splitting projects among teams
-the use of classes allows code to be reused throughout the program(and sometimes in other programs) improving readability and data efficiency
class
a blueprint for objects specifying their properties and methods
properties and methods
data and instructions in a class, respectively
can be public or private(accessible from anywhere in the program, or only from within the object and its inheritors)
class definitions
lists of a class's name, properties and methods in text form
object
containers of data and instructions created from a class
instantiation
the creation of an instance of an object from a class using a constructor
constructor
a method in a class called to create and initialise an object from it, assigning a reference to a variable of the class type
constructors can be implicit(automatic, with default parameters) or explicit(eith user-defined parameters)
encapsulation
the process of combining properties and methods to form a class
inheritance
the process by which a class is given the properties and methods of another class in addition to its own, in an is-a relationship
overriding
when a class inherits another it can override its methods, changing the implementation but keeping the name(for itself, not the inherited class)
association
when classes are connected in 1-1, 1-m or m-m relationships, allows them to interact and collaborate by accessing eachothers' properties and methods
associated objects form part of their container object as a property, in a has-a relationship
aggregation
association where an object will continue to exist if its container object is destroyed
composition
association where an object will cease to exist if its container object is destroyed
polymorphism
where objects are processed differently depending on their class
OOP design principles
-encapsulate what varies
-favour composition over inheritance
-program to interfaces, not implementation
encapsulate what varies
components of a program which are likely to change should be encapsulated as it better protects against said changes unwantedly affecting other parts of the program
favour composition over inheritance
composition should be used over inheritance wherever possible as it is seen as more flexible
program to interfaces, not implementation
programming to depend on interfaces rather than implementations improves code flexibility, and allows unrelated classes to easily make use of similar methods
interface
a set of abstract procedures determining what methods an object should have, without providing the code for them
implementations
classes that fulfil the rules determined by interfaces and provide the code
class diagrams
used to visually represent the relationships that exist between classes
classes are represented by boxes with different connectors representing different kinds of relationship, can exhibit various levels of detail
inheritance diagrams
sshow inheritance relationships that exist between classes- unfilled arrows point from classes to their inheritees and always point upwards
association in class diagrams
association is shown in class diagrams using diamond headed arrows, unfilled and filled diamonds correspond to aggregation and composition respectively
association in UML
in unified modelling language, association between two classes is modelled using lines
a normal line represents bidirectional association while a line with an arrow represents one-way association where a class can call the one the arrow is pointing to but not vice versa
class diagrams with properties and methods
class boxes are split into three, containing the class's name, properties and methods from top to bottom respectively
plus and minus signs in front of properties and methods denote they are public and private respectively
hashtags indicate protected properties or methods