Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented.

Similar presentations


Presentation on theme: "Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented."— Presentation transcript:

1 Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented paradigm, e.g. C++, Java Main advantage of object-oriented programming (OOP) is reuse.

2 Object-Oriented Design (OOD) The first step of object-oriented programming (OOP) is OOD. OOD will be written in UML (Unified Modeling Language) Writing an object-oriented program: Construct an OOD Convert the OOD to a particular programming language

3 OOD Concepts Objects classes instances of classes Association Inheritance superclasses subclasses

4 What is an object? OOP involves defining a number of objects. Objects consist of attributes and operations that can be applied to the data. The attributes of an object can only be accessed via these operations. The operations are used to access and update/change the data. Objects are transient, i.e. the data and operations of an object only remain in memory for the duration the program is run.

5 student Object Attributes Name Student number Address Matric points Degree Operations Set name, student number, address, matric points or degree Get name, student number, address, matric points or degree Print student information

6 customer Object Attributes Name Address Phone Balance Operations Set name, address, phone or balance Get name, address, phone or balance Update balance Print customer details

7 Classes and Instances A class defines the overall internal structure, i.e. attributes and operations, of the object. Class definition Attributes called data elements Operations called methods An instance of a class which has specific values for the different data elements. One of the data elements my be used to identify each element uniquely, e.g. a student number.

8 Instance of the student class Name: B. Green Student Number: 203456789 Address: WOB Residence Matric Points: 45 Degree: B.Sc

9 Encapsulation Classes are said to exhibit “information hiding” due to the fact that the internal structure of the class is hidden. The data elements of an instance of the class is manipulated be means of an interface, e.g. the Formatter and Keyboard classes. This is referred to as encapsulation.

10 Class Diagrams In UML class diagrams are used to represent classes and relationships between classes. Each class is represented as a box divided into three parts specifying the: Name of the class Data elements of the class Attributes of the class

11 The student class Class name Data elements Methods

12 Example 1 Define the classes that you would use for the following system. Specify the data elements and methods of each class. You need to develop a system that keeps track of customers accounts. Information stored for each customer is the customer name, address and phone number. A customer may place one or more orders. Each order has an order number, date and amount and a description of the product to be shipped. Each product has a unique product number, description and price.

13 Example 2 Define the classes that you would use for the following system. Specify the data elements and methods of each class. You are required to develop a GUI for an existing application. The main component of the GUI is a form. The form has a width, height, boarder style and background color. The user must be able to display or close a form. The user must also be able to minimize and maximize the form. The form contains labels and buttons. Labels have a size, shape, color and text. The programmer must be able to set the text, get the text, hide the label or display the label. Each button has a size, shape, colour, location and caption. The user should be able to click the button. A programmer must be able to hide, display, enable or disable the button.


Download ppt "Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented."

Similar presentations


Ads by Google