Programming Paradigms
Programming Paradigms
Imperative
Explicit sets of commands that specify how to solve
- Structured
- Programming to interfaces with clear control flow
- Procedural
- Using subroutines to carry out specific tasks on data
- Object Oriented
- Using objects to combine behaviour and data
Declarative
Expressing what the program should solve
E.g. SQL: SELECT Name, Address FROM Employees;
- Functional
- Expresses problems as a series of functions and functions calls
1. Imperative
E.g. Free Basic
2. Functional
Good when you have a fixed set of things, and as your code evolves, you primarily
add new operations on those existing things
Remove side effects
Directly links input to output
3. Logic
E.g. Prolog
4. Object Oriented
E.g. Java & Python
Good when you have a fixed set of operations on things
Classes
- Contain attributes & methodsProduce “objects”
Inheritance
- Subclasses inherit all the attributes and methods of the superclass. These
subclasses act as extensions to the superclasses.
Abstraction
- The process of designing classes so they are reduced to their necessary attributes and methods
Attributes are meaningful information that are treated as characteristics or features
Objects have behaviours, these are called ‘methods’ or ‘functions’ (not the same thing)
Methods are like actions
Objects interact with each other, dynamic interactions
Users initiate object activity, events and input get started in ‘Main’
Stub: situation in code where it is still under development. E.g. a button that returns a message that it isn’t
finished yet instead of completing its action.
System.out.println(p.colour);
System.out.println(p.point);
System.out.println(p.type);
System.out.println(p.clicked);
p.click
System.out.println(p.clicked);