Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.

Slides:



Advertisements
Similar presentations
An Introduction to Programming General Concepts. What is a program? A program is an algorithm expressed in a programming language. programming language.
Advertisements

Structures. Procedural (Imperative) Languages Procedural languages work on the basis of explicitly telling the computer ‘how to do something’; by using.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
OOP: Creating Object-Oriented Programs. VB & Object Oriented Programming Objects have properties, methods, and generate events Classes have been predefined.
Computers: Tools for an Information Age
Object-oriented Programming Concepts
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Copyright © 2001 by Wiley. All rights reserved. Chapter 1: Introduction to Programming and Visual Basic Computer Operations What is Programming? OOED Programming.
BACS 287 Basics of Object-Oriented Programming 1.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Programming Languages – Coding schemes used to write both systems and application software A programming language is an abstraction mechanism. It enables.
Object Oriented Software Development
Programming Languages and Paradigms Object-Oriented Programming.
Languages and Environments Higher Computing Unit 2 – Software Development.
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
Microsoft Visual Basic 2005: Reloaded Second Edition
An Object-Oriented Approach to Programming Logic and Design
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Programming Paradigms
BIT 1003 – Presentation 7. Contents GENERATIONS OF LANGUAGES COMPILERS AND INTERPRETERS VIRTUAL MACHINES OBJECT-ORIENTED PROGRAMMING SCRIPTING LANGUAGES.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
CHAPTER ONE Problem Solving and the Object- Oriented Paradigm.
Event Driven Programming
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Computer Concepts 2014 Chapter 12 Computer Programming.
The Teacher Computing Computer Languages [Computing]
Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.
Computer Programs and Programming Languages What are low-level languages and high-level languages? High-level language Low-level language Machine-dependent.
CHAPTER ONE Problem Solving and the Object- Oriented Paradigm.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
Chapter 12 Computer Programming. Chapter Contents Chapter 12: Computer Programming 2  Section A: Programming Basics  Section B: Procedural Programming.
Working With Objects Tonga Institute of Higher Education.
Principles of Software Development 1 Principles Of Software Design and Development Types of language / Choosing a language.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Module 4 Part 2 Introduction To Software Development : Programming & Languages Introduction To Software Development : Programming & Languages.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
I Power Higher Computing Software Development Development Languages and Environments.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
1.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Chapter 12: Computer Programming 1 Computer Programming Chapter 12.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented.
Software Design and Development Languages and Environments Computing Science.
 By the end of this lecture, you should …  Understand the three pillars of Object- Oriented Programming: Inheritance, Encapsulation and Polymorphism.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
PROGRAMMING (1) LECTURE # 1 Programming and Languages: Telling the Computer What to Do.
Computer Languages [Computing] Computing.
Programming paradigms
Section 2.1: Programming paradigms
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Microsoft Visual Basic 2005: Reloaded Second Edition
An Introduction to Programming
Section 2.1: Programming paradigms
Developing Applications
Computer Programming.
VISUAL BASIC.
Chapter 12: Computer Programming
PROGRAMMING PARADIGMS
Event Driven Programming
CS285 Introduction - Visual Basic
Overview of Programming Paradigms
An Introduction to Programming
Programming Languages and Paradigms
Presentation transcript:

Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming language can use one or multiple styles

Imperative programming Programs written in a sequence of instructions – the program is executed in order the programmer designs Fortran and Cobol are examples of imperative languages Pascal, C and Ada also use the imperative model Imperative programs work and manipulate with variables and data structures (e.g. Arrays, records etc)

Functional Programming Functional languages programs define mathematical functions There are NO variables or assignment statements Functional languages provide MODELS of mathematical functions The classic example is HASKELL and the factorial algorithm

Functional cont. 5! (5 factorial) = 5 * 4 * 3 * 2 * 1 In Haskell this looks like: – Let fac n = if n == 0 then 1 else n * fac (n-1) – This looks nasty but what it does: Let fac n =...create a function called fac (based on input n) If n == 0 then... If n is 0 then 1... Return n = 1 Else n * fac (n-1)... Otherwise return n * fac (n-1). Fac(n-1) actually calls the function fac again – but this time with n – 1 – So what happens if you input: fac 5 ? Is n == 0? No – go to the else condition 5 * fac (5-1) – call fac 4 – Is n == 0? No – go to the else condition – 4 * fac (4-1) – call fac 3 » Is n == 3? No – go to the else condition » 3 * fac (3 – 1) – call fac 2 So we’ll end up with: 5 * (5-1) * (4-1) * (3-1) * (2-1) * (1-1) * 1 (because n==0) The 1 finishes the algorithm because it doesn’t call itself anymore – An algorithm that calls itself is known as a recursive algorithm and we’ll look at them in more detail later on

Logic Programming Logic programming languages are made of sets of facts and rules They are often used to develop AI type systems (e.g. ELIZA – the online therapist) The best known language is Prolog – SWI- Prolog is a an example implementation

Event driven programming Sub routines / functions / procedures are not executed in a specific order – but according to events that are triggered (usually by a user) E.g. The print button in Word triggers a ‘click’ event which then runs the print procedure Delphi, Visual Basic.Net and Python are all examples of languages that can use event driven programming

Event Driven Programming cont. Event Trigger --> action which gets the program to execute your code e.g. click, mouse_move, etc The event trigger --> runs a sub procedure / event sub procedures The sender: control that triggered the event The receiver: usually the event sub procedure. It is told to HANDLE the e.g. click event of the button --> the handler Event arguments (eventargs): data that the sender passes to the event sub procedure, e.g. the key that you typed into a textbox

Event driven programming cont. Uses objects (e.g. forms, buttons, textboxes) as the controls which trigger the events Used to develop: programs that need GUIs, programs that need to be developed quickly (RAPID APPLICATION DEVELOPMENT), applications where the USER is the main focus Usually developed using visual tools and techniques where the interface is developed separately from the code Event driven programs can be prototyped very quickly Often event driven languages have built in wizards/functionality to access advanced facilities quickly (databases, web browsers, drop down menus) You can add components to your event driven language (e.g. a media player, an RSS reader control)

Object oriented programming Forget about computers for a moment A class: car Properties: colour, size, number of wheels Methods: (things it can do) drive, accelerate, brake, crash (ok, not really) How do you create a new car from the car class? You instantiate it – or in English, you create a new car object The new car object (banger) inherits all of the properties and methods of the car class – the process is called inheritance Back to programming: – There’s a class in VB called the button class What properties might it have? What methods might it have? – When you create a new button object (btngo) you __________ it – When you create btngo what does it get? What’s that called?

Object oriented programming cont. Step 1: Name the class. Step 2: Decide on the properties of the class. Step 3: Declare properties as private. Step 4: Declare the constructor of the class. A constructor is procedure that is automatically invoked when an object is first instantiated (created from the class). In VB this is done for you automatically – but not in most languages! Step 5: Declare the methods (procedures and functions). Step 6: Write the code for your methods.

A basic OOP class in Pascal Step 1: Create the class (As a type) Step 2: Declare properties as private. Step 4: Create the public methods (procedures and functions), including the constructor Step 5: Create the class functions and procedures

12 Summary Properties of a class are declared as private. This is so they cannot be accessed outside the class. Methods (procedures and functions) are public and are written to enable the properties of the class to be accessed from outside the class. A constructor is a special method that is used when a new object is created of that class. When an object is created it has all the methods and variables defined in the class. Encapsulation is a term used to describe the combination of the object and its methods. This promotes separation of the implementation and the interface. Because the properties of the class are private, you can control changes to the actual object. In addition, you have the flexibility to change the implementation without affecting anything outside the class. This principle is known as information hiding. Inheritance is where one class can inherit methods and properties from another class. This promotes efficiency because code from one class can be reused in its sub-class.

Inheritance Diagrams AnimalVertebratesMammalsHumanReptilesCrocodileInvertebratesInsectsSpiderCrustaceansCrabMollusksOctopus

Class Diagram