Object-oriented programming

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Introduction to Java 2 Programming
General OO Concepts Objectives For Today: Discuss the benefits of OO Programming Inheritance and Aggregation Abstract Classes Encapsulation Introduce Visual.
OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Introduction to Object Oriented Programming Java.
More about classes and objects Classes in Visual Basic.NET.
CS-2135 Object Oriented Programming
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
ISE 582: Web Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 4 JAVA Cup.
BACS 287 Basics of Object-Oriented Programming 1.
2.5 OOP Principles Part 1 academy.zariba.com 1. Lecture Content 1.Fundamental Principles of OOP 2.Inheritance 3.Abstraction 4.Encapsulation 2.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
An Object-Oriented Approach to Programming Logic and Design
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
 Computer Science 1MD3 Introduction to Programming Michael Liut Ming Quan Fu Brandon.
Object Oriented Programming
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Chapter More on Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Exceptions and Handling
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Introduction to Object-oriented Programming
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Section 2.1: Programming paradigms
Programming Logic and Design Seventh Edition
Objects as a programming concept
The Object-Oriented Thought Process Chapter 1
Object-Orientated Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Section 2.1: Programming paradigms
Object-oriented programming
Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.
To Get Started Paper sheet
Object Oriented Analysis and Design
Chapter 10 Thinking in Objects
Object-oriented programming
Inheritance Basics Programming with Inheritance
Teaching Computing to GCSE
Corresponds with Chapter 7
Chapter 10 Thinking in Objects
Teach A-Level Computer Science: Object-Oriented Programming in Python
Week 6 Object-Oriented Programming (2): Polymorphism
Teach A-Level Computer Science: Object-Oriented Programming in Python
Advanced Programming Behnam Hatami Fall 2017.
Programming paradigms
Features of OOP Abstraction Encapsulation Data Hiding Inheritance
Computer Programming with JAVA
Java Programming, Second Edition
Inheritance.
Object-Oriented Programming
By Rajanikanth B OOP Concepts By Rajanikanth B
Object Oriented Programming in A Level
Object Oriented Programming in A Level
Object Oriented Analysis and Design
Object-Oriented Programming
Object Oriented Design & Analysis
Extending Classes Through Inheritance
ADVANCED OBJECT-ORIENTED PROGRAMMING
C++ Object Oriented 1.
Presentation transcript:

Object-oriented programming Session 4 Class Diagrams, Composition and Aggregation

Course Outline Week No Understanding Developing programming skills Week 1 – Introduction to Classes and Objects Week 1 – OOP Programming basics Week-2 Week 2 – Variables and objects, Python Modules Week 2- Creating and using Python modules Week-3 Week 3 – Inheritance Week 3 – Programming using Inheritance Week-4 Week 4 – Class Diagrams Week 4 – Composition and Aggregation Week-5 Week 5 - Polymorphism Week 5 - Consolidation

Session 4 Outline To be able to read and draw class diagrams To understand the difference between private, public and protected attributes To be able to implement a “has-a” relationship (aggregation/ composition) To understand the encapsulation principle To consolidate understanding of inheritance

Specification check From AQA From CIE From OCR ( plus other details … )

Recap: Inheritance One class can inherit methods and variables from another class This is called inheritance For example, in a system for a school, there may be a Student class and a Staff class (enabling you to create Student and Staff objects) There also may be TeachingStaff, SupportStaff, ManagementStaff classes. These could inherit methods and variables from the Staff object. In this case Staff is the super class and TeachingStaff is the sub class (or child class)

Private, public & protected Theoretically, the parts of a class declaration are declared to be private OR public a private section for the state (member data – ie attributes) a public section for the behaviour(operations, member functions) The keywords “private” and “public” control the accessibility of the member data and functions Private or protected attributes cannot be accessed outside of the class Public methods can be accessed outside the class Private and public are not implemented in Python but are needed for examination answers In other OOP languages A private member is only accessible within the same class as it is declared. A protected member is accessible within all classes in the same package and within subclasses in other packages. A public member is accessible to all classes

Encapsulation This is an important principle of OOP, associated with abstraction or information hiding Encapsulation means that the internal representation of an object cannot be seen from outside of the object’s definition It is achieved by making attributes private (or protected). The attributes are only accessed through methods (public) Get and set methods are written to access the data This protects the object from being changed in an irregular way and allows groups of developers to all access the same class, via the methods.

Class Diagrams class name attributes methods - private + public

Composition and aggregation contd Composition is where one object is composed (or made up of) two or more existing objects and is entirely dependent on those objects for its own existence (from Hodder AQA materials) Association aggregation is where an object is made up of one or more objects but is not entirely dependent on those objects for its own existence (from Hodder’s AQA materials) For example, a teaching group is made up of students: this is aggregation as the students will belong to other teaching groups too. A teaching group also has to have a teacher. This can be argued to be the stronger case of composition.

Composition & Aggregation (association) Composition and aggregation are both “has-a” relationships that can be hard to distinguish. The strongest relationship is composition, then aggregation and then association. AQA talk about all three in their resources but the spec mentions composition aggregation and association aggregation.

Activity 1 Edit the class diagram to include a Teaching group – add the attributes name, room number and subject and student_list and two methods to a) add a student to the teaching group and b) return the room number, name and subject of the teaching group Composition aggregation (for AQA examinations) Association aggregation (for AQA examinations)

Possible answer Gliffy can be used to create Class Diagrams (14 day free trial) – or just do them in powerpoint

Difference between Python & pseudocode Pseudocode (exam questions) class Pet private name public procedure new(givenName) name=givenName endprocedure endclass class Dog inherits Pet private breed public procedure new(givenName, givenBreed) super.new(givenName) breed=givenBreed endprocedure endclass Note that Python does not mention private and public This is OCR pseudocode but they are all similar

Activity: Past paper question Answer examination question June 2015 AQA Comp 3 See handout Draw an inheritance diagram Write a class definition in pseudocode

Let us continue after break