0% found this document useful (0 votes)
13 views40 pages

CSC 409 Unit 3

The document outlines the course CSC 409 on Structured Programming, detailing its objectives, course description, and the fundamental concepts of programming paradigms. It covers low-level, procedural, and object-oriented programming, emphasizing the importance of structured programming for improving code reliability and maintainability. The course aims to equip students with skills to implement programming methodologies and design constructs using C++.

Uploaded by

dfwsarahhhh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views40 pages

CSC 409 Unit 3

The document outlines the course CSC 409 on Structured Programming, detailing its objectives, course description, and the fundamental concepts of programming paradigms. It covers low-level, procedural, and object-oriented programming, emphasizing the importance of structured programming for improving code reliability and maintainability. The course aims to equip students with skills to implement programming methodologies and design constructs using C++.

Uploaded by

dfwsarahhhh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Structured Programming

Course code: CSC 409


Credit Units: 3
Lecturers/Course coordinator Dr. E. O. Oyekanmi
Office: Computer Science Department
Phone: 08036427123
Email: [email protected]
Class Hours: (Monday, from 8.00 am to 10.00 am)
Office Hours: M, T, W, Th (from 2.00 pm to 4.00 pm)
Online Hours: M, T, W, Th, F, Sa (from 6.00 pm to 8.00 pm)
Course Description
There are several programming languages before now, however not all of them are
structured. The purpose of the structured ones are:
 improve programme dependability and programmers' understanding.
Three hows of programming:
 how to develop the solution to a given problem,
 how to organise a programme, and
 how to effectively use the standard techniques that represent the "tricks" of the
programming trade.
Three basic building blocks of structured programming
 Sequential, conditional, and repeating structured codes which are the are discussed in
details.
 These three components replace the need for GO TO commands to control the flow of
a programme.
Overall, this course will ensure that a programmer has greater confidence on a developed software code in
terms of simplicity to grasp and reduction of logical errors, because the programme is built of highly
independent modules.
Course Objectives
At the end of this course, students should be able to:
 explain the rationale behind structured programming paradigms.
 differentiate among three main approaches for writing a computer program
 compare and contrast between structured programming and procedural
coding.
 Interpret programming language with built-in structured programming styles
 implement programming methodology.
 Design language construct using C++.
 describe discipline of programming.
 demonstrate the use of structure programming in database.
Unit 3: Comparative study of programming paradigm

In this unit you will understand the following topics

 3.1 Low-level programming paradigm.


 3.2. The concept behind procedural programming.
 3.3. Object-Oriented Programming
 3.4. Declarative Programming Style
Learning Objectives
 Learn about different programming paradigms
 Concepts and particularities
 Advantages and drawbacks
 Application domains

Comparative Study of Programming


Languages 5
Introduction
 A programming paradigm is a fundamental style of computer programming.
 Compare with a software development methodology, which is a style of solving
specific software engineering problems.
 Different methodologies are more suitable for solving certain kinds of problems or
applications domains.
 Same for programming languages and paradigms.
 Programming paradigms differ in:
 the concepts and abstractions used to represent the elements of a program (such
as objects, functions, variables, constraints, etc.)
 the steps that compose a computation (assignation, evaluation, data flow, control
flow, etc.).
Comparative Study of Programming
Languages 6
7
Programming
paradigms

Comparative Study of
Programming Languages
Low-level
8
programming
paradigm

Comparative Study of
Programming Languages
Low level
 Initially, computers were hard-wired or soft-wired and then later
programmed using binary code that represented control sequences
fed to the computer CPU.

 This was difficult and error-prone. Programs written in binary are said to
be written in machine code, which is a very low-level programming
paradigm. Hard-wired, soft-wired, and binary programming are
considered first generation languages.

Comparative Study of Programming


Languages 9
Low level
 To make programming easier, assembly languages were developed.
 These replaced machine code functions with mnemonics and memory
addresses with symbolic labels.
 Assembly language programming is considered a low-level paradigm
although it is a 'second generation' paradigm.
 Assembly languages of the 1960s eventually supported libraries and quite
sophisticated conditional macro generation and pre-processing capabilities.
 They also supported modular programming features such as subroutines,
external variables and common sections (globals), enabling significant code
re-use and isolation from hardware specifics via use of logical operators.

Comparative Study of Programming


Languages 10
Low level
 Assembly was, and still is, used for time-critical systems and frequently in
embedded systems.

 Assembly programming can directly take advantage of a specific computer


architecture and, when written properly, leads to highly optimized code.

 However, it is bound to this architecture or processor and thus suffers from lack of
portability.

 Assembly languages have limited abstraction capabilities, which makes them


unsuitable to develop large/complex software.

Comparative Study of Programming


Languages 11
Procedural
12
programming
paradigm

Comparative Study of
Programming Languages
Procedural programming
 Often thought as a synonym for imperative programming.

 Specifying the steps the program must take to reach the desired state.

 Based upon the concept of the procedure call.

 Procedures, also known as routines, subroutines, methods, or functions that contain a series of
computational steps to be carried out.
 Any given procedure might be called at any point during a program's execution, including by other
procedures or itself.

 A procedural programming language provides a programmer a means to define precisely each step
in the performance of a task. The programmer knows what is to be accomplished and provides
through the language step-by-step instructions on how the task is to be done.
 Using a procedural language, the programmer specifies language statements to perform a
sequence of algorithmic steps.
Comparative Study of Programming
Languages 13
Procedural programming
 Possible benefits:
 Often a better choice than simple sequential or unstructured programming in many situations which involve moderate
complexity or require significant ease of maintainability.
 The ability to re-use the same code at different places in the program without copying it.
 An easier way to keep track of program flow than a collection of "GOTO" or "JUMP" statements (which can turn a
large, complicated program into spaghetti code).
 The ability to be strongly modular or structured.

 The main benefit of procedural programming over first- and second-generation languages is
that it allows for modularity, which is generally desirable, especially in large, complicated
programs.

 Modularity was one of the earliest abstraction features identified as desirable for a
programming language.
Comparative Study of Programming
Languages 14
Procedural programming
 Scoping is another abstraction technique that helps to keep procedures strongly modular.

 It prevents a procedure from accessing the variables of other procedures (and vice-versa),
including previous instances of itself such as in recursion.

 Procedures are convenient for making pieces of code written by different people or different
groups, including through programming libraries.
 specify a simple interface
 self-contained information and algorithmics
 reusable piece of code

Comparative Study of Programming


Languages 15
Procedural programming
 The focus of procedural programming is to break down a programming task into a collection of
variables, data structures, and subroutines, whereas in object-oriented programming it is to
break down a programming task into objects with each "object" encapsulating its own data and
methods (subroutines).

 The most important distinction is whereas procedural programming uses procedures to operate
on data structures, object-oriented programming bundles the two together so an "object"
operates on its "own" data structure.

Comparative Study of Programming


Languages 16
Procedural programming
 The earliest imperative languages were the machine languages of the original computers. In these
languages, instructions were very simple, which made hardware implementation easier, but hindered the
creation of complex programs.
 FORTRAN (1954) was the first major programming language to remove through abstraction the obstacles
presented by machine code in the creation of complex programs.
 FORTRAN was a compiled language that allowed named variables, complex expressions, subprograms,
and many other features now common in imperative languages.
 In the late 1950s and 1960s, ALGOL was developed in order to allow mathematical algorithms to be more
easily expressed.
 In the 1970s, Pascal was developed by Niklaus Wirth, and C was created by Dennis Ritchie.

 For the needs of the United States Department of Defense, Jean Ichbiah and a team at Honeywell began
designing Ada in 1978.

Comparative Study of Programming


Languages 17
Object-oriented
18
programming
paradigm

Comparative Study of
Programming Languages
Object-oriented
programming
 Object-oriented programming (OOP) is a programming paradigm that uses "objects" –
data structures encapsulating data fields and procedures together with their interactions
– to design applications and computer programs.

 Associated programming techniques may include features such as data abstraction,


encapsulation, modularity, polymorphism, and inheritance.

 Though it was invented with the creation of the Simula language in 1965, and further
developed in Smalltalk in the 1970s, it was not commonly used in mainstream software
application development until the early 1990s.

 Many modern programming languages now support OOP.


Comparative Study of Programming
Languages 19
OOP concepts: class
 A class defines the abstract characteristics of a thing (object), including that thing's characteristics (its
attributes, fields or properties) and the thing's behaviors (the operations it can do, or methods,
operations or functionalities).

 One might say that a class is a blueprint or factory that describes the nature of something.

 Classes provide modularity and structure in an object-oriented computer program.

 A class should typically be recognizable to a non-programmer familiar with the problem domain,
meaning that the characteristics of the class should make sense in context. Also, the code for a class
should be relatively self-contained (generally using encapsulation).

 Collectively, the properties and methods defined by a class are called its members.
Comparative Study of Programming
Languages 20
OOP concepts: object
 An object is an individual of a class created at run-time trough object instantiation from a
class.

 The set of values of the attributes of a particular object forms its state. The object consists of
the state and the behavior that's defined in the object's class.

 The object is instantiated by implicitly calling its constructor, which is one of its member
functions responsible for the creation of instances of that class.

Comparative Study of Programming


Languages 21
OOP concepts: attributes
 An attribute, also called data member or member variable, is the data encapsulated within a class or object.

 In the case of a regular field (also called instance variable), for each instance of the object there is an instance variable.

 A static field (also called class variable) is one variable, which is shared by all instances.

 Attributes are an object’s variables that, upon being given values at instantiation (using a constructor) and further
execution, will represent the state of the object.

 A class is in fact a data structure that may contain different fields, which is defined to contain the procedures that act upon it.
As such, it represents an abstract data type.

 In pure object-oriented programming, the attributes of an object are local and cannot be seen from the outside. In many
object-oriented programming languages, however, the attributes may be accessible, though it is generally considered bad
design to make data members of a class as externally visible.
Comparative Study of Programming
Languages 22
OOP concepts: method
 A method is a subroutine that is exclusively associated either with a class (in which case it is
called a class method or a static method) or with an object (in which case it is an instance
method).

 Like a subroutine in procedural programming languages, a method usually consists of a


sequence of programming statements to perform an action, a set of input parameters to
customize those actions, and possibly an output value (called the return value).

 Methods provide a mechanism for accessing and manipulating the encapsulated state of an
object.

 Encapsulating methods inside of objects is what distinguishes object-oriented programming


from procedural programming.
Comparative Study of Programming
Languages 23
OOP concepts: method
 instance methods are associated with an object

 class or static methods are associated with a class.

 The object-oriented programming paradigm intentionally favors the use of methods for each and
every means of access and change to the underlying data:
 Constructors: Creation and initialization of the state of an object. Constructors are called automatically by the run-time
system whenever an object declaration is encountered in the code.
 Retrieval and modification of state: accessor methods are used to access the value of a particular attribute of an
object. Mutator methods are used to explicitly change the value of a particular attribute of an object. Since an object’s
state should be as hidden as possible, accessors and mutators are made available or not depending on the information
hiding involved and defined at the class level
 Service-providing: A class exposes some “service-providing” methods to the exterior, who are allowing other objects
to use the object’s functionalities. A class may also define private methods who are only visible from the internal
perspective of the object.
 Destructor: When an object goes out of scope, or is explicitly destroyed, its destructor is called by the run-time
system. This method explicitly frees the memory and resources used during its execution.

Comparative Study of Programming


Languages 24
OOP concepts: method
 The difference between procedures in general and an object's method is that the method, being
associated with a particular object, may access or modify the data private to that object in a way
consistent with the intended behavior of the object.
 So rather than thinking "a procedure is just a sequence of commands", a programmer using an
object-oriented language will consider a method to be "an object's way of providing a
service“. A method call is thus considered to be a request to an object to perform some task.
 Method calls are often modeled as a means of passing a message to an object. Rather than
directly performing an operation on an object, a message is sent to the object telling it what it
should do. The object either complies or raises an exception describing why it cannot do so.
 Smalltalk used a real “message passing” scheme, whereas most object-oriented languages
use a standard “function call” scheme for message passing.
 The message passing scheme allows for asynchronous function calls and thus concurrency.

Comparative Study of Programming


Languages 25
OOP concepts: inheritance
 Inheritance is a way to compartmentalize and reuse code by creating collections of attributes
and behaviors (classes) which can be based on previously created classes.
 The new classes, known as subclasses (or derived classes), inherit attributes and behavior of
the pre-existing classes, which are referred to as superclasses (or ancestor classes). The
inheritance relationships of classes gives rise to a hierarchy.
 Multiple inheritance can be defined whereas a class can inherit from more than one
superclass. This leads to a much more complicated definition and implementation, as a single
class can then inherit from two classes that have members bearing the same names, but yet
have different meanings.
 Abstract inheritance can be defined whereas abstract classes can declare member functions
that have no definitions and are expected to be defined in all of its subclasses.

Comparative Study of Programming


Languages 26
OOP concepts: abstraction
 Abstraction is simplifying complex reality by modeling classes appropriate to the problem, and
working at the most appropriate level of inheritance for a given aspect of the problem.

 For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and
many more components. To build the Car class, one does not need to know how the different
components work internally, but only how to interface with them, i.e., send messages to them,
receive messages from them, and perhaps make the different objects composing the class
interact with each other.

 Object-oriented programming provides abstraction through composition and inheritance.

Comparative Study of Programming


Languages 27
OOP concepts: encapsulation
and information hiding
 Encapsulation refers to the bundling of data members and member functions inside of a
common “box”, thus creating the notion that an object contains its state as well as its
functionalities
 Information hiding refers to the notion of choosing to either expose or hide some of the
members of a class.
 These two concepts are often misidentified. Encapsulation is often understood as including the
notion of information hiding.
 Encapsulation is achieved by specifying which classes may use the members of an object. The
result is that each object exposes to any class a certain interface — those members accessible to
that class.
 The reason for encapsulation is to prevent clients of an interface from depending on those parts
of the implementation that are likely to change in the future, thereby allowing those changes to be
made more easily, that is, without changes to clients.
 It also aims at preventing unauthorized objects to change the state of an object.
Comparative Study of Programming
Languages 28
OOP concepts: encapsulation
and information hiding
 Members are often specified as public, protected or private, determining whether they are
available to all classes, sub-classes or only the defining class.

 Some languages go further:

 Java uses the default access modifier to restrict access also to classes in the same package

 C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or friend
(VB.NET)

 Eiffel and C++ allow one to specify which classes may access any member of another class (C++ friends)

 Such features are basically overriding the basic information hiding principle, greatly complexify its implementation, and
create confusion when used improperly

Comparative Study of Programming


Languages 29
OOP concepts:
polymorphism
 Polymorphism is the ability of objects belonging to different types to respond to method, field,
or property calls of the same name, each one according to an appropriate type-specific
behavior.
 The programmer (and the program) does not have to know the exact type of the object at
compile time. The exact behavior is determined at run-time using a run-time system behavior
known as dynamic binding.
 Such polymorphism allows the programmer to treat derived class members just like their parent
class' members.
 The different objects involved only need to present a compatible interface to the clients. That
is, there must be public or internal methods, fields, events, and properties with the same name
and the same parameter sets in all the superclasses, subclasses and interfaces.
 In principle, the object types may be unrelated, but since they share a common interface, they
are often implemented as subclasses of the same superclass.

Comparative Study of Programming


Languages 30
OOP concepts:
polymorphism
 A method or operator can be abstractly applied in many different situations. If a Dog is
commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this
may elicit an oink(). They both inherit speak() from Animal, but their derived class methods
override the methods of the parent class. This is overriding polymorphism.

 Overloading polymorphism is the use of one method signature, or one operator such as "+",
to perform several different functions depending on the implementation. The "+" operator, for
example, may be used to perform integer addition, float addition, list concatenation, or string
concatenation. Any two subclasses of Number, such as Integer and Double, are expected to
add together properly in an OOP language. The language must therefore overload the addition
operator, "+", to work this way. This helps improve code readability. How this is implemented
varies from language to language, but most OOP languages support at least some level of
overloading polymorphism.

Comparative Study of Programming


Languages 31
OOP concepts:
polymorphism
 Many OOP languages also support parametric polymorphism, where code is written without
mention of any specific type and thus can be used transparently with any number of new types.
C++ templates and Java Generics are examples of such parameteric polymorphism.

 The use of pointers to a superclass type later instantiated to an object of a subclass is a simple
yet powerful form of polymorhism, such as used un C++.

Comparative Study of Programming


Languages 32
OOP: Languages
 Simula (1967) is generally accepted as the first language to have the primary features of an
object-oriented language. It was created for making simulation programs, in which what came to
be called objects were the most important information representation.

 Smalltalk (1972 to 1980) is arguably the canonical example, and the one with which much of the
theory of object-oriented programming was developed.

Comparative Study of Programming


Languages 33
OOP: Languages
 Concerning the degree of object orientation, following distinction can be made:

 Languages called "pure" OO languages, because everything in them is treated consistently as an object, from primitives
such as characters and punctuation, all the way up to whole classes, prototypes, blocks, modules, etc. They were
designed specifically to facilitate, even enforce, OO methods. Examples: Smalltalk, Eiffel, Ruby, JADE.

 Languages designed mainly for OO programming, but with some procedural elements. Examples: C++, C#, Java, Scala,
Python.

 Languages that are historically procedural languages, but have been extended with some OO features. Examples: VB.NET
(derived from VB), Fortran 2003, Perl, COBOL 2002, PHP.

 Languages with most of the features of objects (classes, methods, inheritance, reusability), but in a distinctly original form.
Examples: Oberon (Oberon-1 or Oberon-2).

 Languages with abstract data type support, but not all features of object-orientation, sometimes called object-based
languages. Examples: Modula-2, Pliant, CLU.
Comparative Study of Programming
Languages 34
OOP: Variations
 There are different ways to view/implement/instantiate objects:

 Prototype-based
 objects - classes + delegation

 no classes
 objects are a set of members
 create ex nihilo or using a prototype object (“cloning”)

 Hierarchy is a "containment" based on how the objects were created using prototyping. This hierarchy
is defined using the delegation principle can be changed as the program executes prototyping
operations.

 examples: ActionScript, JavaScript, JScript, Self, Object Lisp


Comparative Study of Programming
Languages 35
OOP: Variations
 object-based
 objects + classes - inheritance

 classes are declared and objects are instantiated


 no inheritance is defined between classes
 No polymorphism is possible

 example: VisualBasic

Comparative Study of Programming


Languages 36
OOP: Variations
 object-oriented
 objects + classes + inheritance + polymorphism

 This is recognized as true object-orientation

 examples: Simula, Smalltalk, Eiffel, Python, Ruby, Java, C++, C#, etc...

Comparative Study of Programming


Languages 37
Declarative
38
Programming
paradigm

Comparative Study of
Programming Languages
Declarative Programming
 General programming paradigm in which programs express the logic of a computation without describing its control flow.

 Programs describe what the computation should accomplish, rather than how it should accomplish it.

 Typically avoids the notion of variable holding state, and function side-effects.

 Contrary to imperative programming, where a program is a series of steps and state changes describing how the
computation is achieved.

 Includes diverse languages/subparadigms such as:


 Database query languages (e.g. SQL, Xquery)
 XSLT
 Makefiles
 Constraint programming
 Logic programming
 Functional programming

Comparative Study of Programming


Languages 39
Assignment
 Compare and Contrast between Procedural and Object-Oriented programming

You might also like