0% found this document useful (0 votes)
46 views21 pages

Preview File1

The document outlines the course objectives, topics, and learning outcomes for a computing course focused on object-oriented programming and generic programming concepts. It covers essential programming principles, encapsulation, inheritance, and the use of templates in C++. Additionally, it discusses the historical context and advantages of generic programming in various programming languages.

Uploaded by

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

Preview File1

The document outlines the course objectives, topics, and learning outcomes for a computing course focused on object-oriented programming and generic programming concepts. It covers essential programming principles, encapsulation, inheritance, and the use of templates in C++. Additionally, it discusses the historical context and advantages of generic programming in various programming languages.

Uploaded by

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

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 2


DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 3
DEPARTMENT OFDEPARTMENT
COMPUTING,OF COMPUTING, FCIT, FCIT, INDUS UNIVERSITY
INDUS UNIVERSITY 4
Course Objectives

To describe programming, algorithm and its structure, sequences, loops and control flow structure.
To illustrate the structured and objective oriented programming, pointer declaration and initialization.
To demonstrate the applications of encapsulation and data hiding, specifies, constructors and inheritance.
To analyze various types of aggregation, composition, overriding, latch and C++

• Course Topics / Major Contents



Introduction to object oriented design, history and advantages of object oriented design, introduction to object oriented programming
concepts, classes, objects, data encapsulation, constructors, destructors, access modifiers, const vs non-const functions, static data
members & functions, function overloading, operator overloading, identification of classes and their relationships, composition,
aggregation, inheritance, multiple inheritance, polymorphism, abstract classes and interfaces, generic programming concepts,
function & class templates, standard template library, object streams, data and object serialization using object streams, exception
handling.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Course Learning Outcomes (CLOs)

CLO’s CLO Description PLOs


PLO-1 (C2 -
CLO-1 Understand principles of object oriented paradigm.
Understand)
Identify the objects & their relationships to build object
CLO-2 PLO-3 (C3 - Apply)
oriented solution
Model a solution for a given problem using object oriented
CLO-3 PLO-3 (C3 - Apply)
principles
PLO-2 (C4 -
CLO-4 Examine an object oriented solution
Analyzing)

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


RECOMMENDED BOOKS

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Week Thirteen weeksTopics

▶ Generic Programming Concepts


▶ Functions
▶ Class Templates

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts

Generic programming is one popular type of computer


programming written in such a way that it creates the most efficient code
possible while allowing the code to apply to as many situations as possible
without requiring any changes to the original code itself.

Once the code is written, it can only perform the exact functions it was
written for. By using generic programming to create codes that work in a
number of different situations, while still performing the same basic, overall
function, programmers can use a single piece of code in different programs
without ever making changes to the original.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts
During the 1970s, generic programming made its debut in the Ada and CLU
programming languages. Soon after, other programming languages such as Java
and C++ began to use generic programming to simplify programming code
while allowing the same code to be used in multiple scenarios. Each

programming language has a particular way of using this code and different
terms to describe it. "Generics," "templates," and "parameterized types" have all
been used at some point or another to refer to instances of generic
programming.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts

Generic programming is a style of computer programming in which algorithms are written in


terms of types to-be-specified-later that are then instantiated when needed for specific types
provided as parameters.

This approach, pioneered by the ML programming language in 1973, permits writing common
functions or types that differ only in the set of types on which they operate when used, thus
reducing duplication. Such software entities are known as generics in Python, Ada, C#, Delphi,
Eiffel, F#, Java, Nim, Rust, Swift, TypeScript and Visual Basic. NET.

They are known as parametric polymorphism in ML , Scala , Julia , and Haskell (the Haskell
community also uses the term "generic" for a related but somewhat different concept); templates
in C++ and D; and parameterized types in the influential 1994 book Design Patterns.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts
Stepanov–Musser and other generic programming paradigms

Generic programming is defined in Musser & Stepanov (1989) as follows,


Generic programming centers around the idea of abstracting from concrete, efficient algorithms to
obtain generic algorithms that can be combined with different data representations to produce a
wide variety of useful software.

Musser, David R.; Stepanov, Alexander A., Generic Programming


Generic programming paradigm is an approach to software decomposition whereby fundamental
requirements on types are abstracted from across concrete examples of algorithms and data structures
and formalized as concepts, analogously to the abstraction of algebraic theories in abstract algebra.
Early examples of this programming approach were implemented in Scheme and Ada, although the
best known example is the Standard Template Library (STL), which developed a theory of iterators that
is used to decouple sequence data structures and the algorithms operating on them.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts

Programming language support for genericity

Genericity facilities have existed in high-level languages since at least the 1970s in languages such as ML,
CLU and Ada, and were subsequently adopted by many object-based and object-oriented languages, including
BETA, C++, D, Eiffel, Java, and DEC's now defunct Trellis-Owl language.

In object-oriented languages

When creating container classes in statically typed languages, it is inconvenient to write specific
implementations for each datatype contained, especially if the code for each datatype is virtually
identical. For example, in C++, this duplication of code can be circumvented by defining a class
template:

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts
In object-oriented languages Class Templates

When creating container classes in statically typed languages, it is inconvenient to write specific
implementations for each datatype contained, especially if the code for each datatype is virtually
identical. For example, in C++, this duplication of code can be circumvented by defining a class
template:

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts
In object-oriented languages Class Templates

Above, T is a placeholder for whatever type is specified when the list is created. These "containers-of-
type-T", commonly called templates, allow a class to be reused with different datatypes as long as certain
contracts such as subtypes and signature are kept. This genericity mechanism should not be confused
with inclusion polymorphism, which is the algorithmic usage of exchangeable sub-classes: for instance, a
list of objects of type Moving_Object containing objects of type Animal and Car. Templates can also be
used for type-independent functions as in the Swap example below:

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts in C++
Generic Programming Concepts in C++

Generic Programming enables the programmer to write a general algorithm


which will work with all data types. It eliminates the need to create different
algorithms if the data type is an integer, string or a character. Once written it
can be used for multiple times and cases

Generic functions are functions declared with one or more generic type
parameters. They may be methods in a class or struct , or standalone functions.
A single generic declaration implicitly declares a family of functions that differ
only in the substitution of a different actual type for the generic type parameter

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts in C++ ,class template, function and object

Generic functions can be overloaded based on signature


or arity, the number of type parameters on a function.
Also, generic functions can be overloaded with non-
generic functions of the same name, as long as the
functions differ in some type parameters. For example, the
following functions can be overloaded:

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts in C++ ,class template, function and object

• The following example uses a generic function


to find the first element in an array. It declares
MyClass, which inherits from the base class
MyBaseClass. MyClass contains a generic
function, MyFunction, which calls another
generic function, MyBaseClassFunction,
within the base class. In main, the generic
function, MyFunction, is called using different
type arguments.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Generic Programming Concepts in C++ ,class
template, function and object

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Reference Books
C++ How To Program 10th Edition Deitel & Deitel
Objet oriented Programming in C++ 3rd Edition By Robert Lafore

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Thanks

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY

You might also like