Lilian Blot Announcements The TPOP problem class this afternoon:  group 1 should come at 3.30pm and group 2 at 4pm. Teaching Evaluation Form  week 9.

Slides:



Advertisements
Similar presentations
Lilian Blot Announcements Teaching Evaluation Form week 9 practical session Formative Assessment week 10 during usual practical sessions group 1 Friday.
Advertisements

Lilian Blot Recursion Autumn 2012 TPOP 1. Lilian Blot Recursion Autumn 2012 TPOP 2.
Lilian Blot PART V: FUNCTIONS Core elements Autumn 2013 TPOP 1.
CIT 590 Intro to Programming Classes. Schedule change The upcoming HW (HW6) is your last major Python HW. It will involve object oriented programming.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
Comp1004: Building Better Classes II Software Design Partly based on BlueJ Book – Chapter 7.
Lilian Blot BUILDING CLASSES Java Programming Spring 2014 TPOP 1.
Lilian Blot TOWARDS MORE ADVANCED CONCEPTS & OBJECT ORIENTED PROGRAMMING Building Data Structure Autumn 2014 TPOP 1.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
OBJECT-ORIENTED PROGRAMMING. What is an “object”? Abstract entity that contains data and actions Attributes (characteristics) and methods (functions)
Lilian Blot LINEAR DATA STRUCTURE LINKED LIST Abstract Data Structure Autumn 2014 TPOP 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Classes and Object- Oriented Programming.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 4.0.
Objects First With Java A Practical Introduction Using BlueJ Designing object-oriented programs How to write code in a way that is easily understandable,
A Brief Introduction to Software Design and Design Quality By Laura Leventhal.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
Designing Classes How to write classes in a way that they are easily understandable, maintainable and reusable.
Design: Coupling and Cohesion How to write classes in a way that they are easily understandable, maintainable and reusable.
Object-Orientated Design Unit 3: Objects and Classes Jin Sa.
ASP.NET Programming with C# and SQL Server First Edition
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 7 Object-Oriented Programming.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
Lilian Blot INHERITANCE Object Oriented Programming Spring 2014 TPOP 1.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
Centre for Computer Technology ICT115 Object Oriented Design and Programming Week 2 Intro to Classes Richard Salomon and Umesh Patel Centre for Information.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Introduction to Object-oriented programming and software development Lecture 1.
© 2008 Dr. Paul Walcott – The University of the West Indies: Cave Hill CampusDr. Paul Walcott COMP6325 Advanced Web Technologies Dr. Paul Walcott The University.
CSE 303 – Software Design and Architecture
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 3.0.
Systems Analysis and Design in a Changing World, 3rd Edition
Designing Classes 2 How to write classes in a way that they are easily understandable, maintainable and reusable.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Views of Data Data – nouns of programming world the objects that are manipulated information that is processed Humans like to group information Classes,
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
Object Oriented Programing (OOP)
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
Or how to work smarter when building solutions.  2:30 – 3:30 Mondays – focus on problem solving (with some terminology thrown in upon occasion)  All.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Objects First With Java A Practical Introduction Using BlueJ Designing classes How to write classes in a way that they are easily understandable, maintainable.
1 COS 260 DAY 12 Tony Gauvin. 2 Agenda Questions? 5 th Mini quiz –Chapter 5 40 min Assignment 3 Due Assignment 4 will be posted later (next week) –If.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
1 Using const in C++ Classes In the presence of pointers we must take steps to ensure the integrity of the object Can use const method definitions The.
Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 6.0.
Object-Oriented Programming Concepts
Classes (Part 1) Lecture 3
Chapter 7 Object-Oriented Programming
Object Oriented Programming
COMPSCI 107 Computer Science Fundamentals
CHAPTER 5 GENERAL OOP CONCEPTS.
Classes and OOP.
Topics Procedural and Object-Oriented Programming Classes
To Get Started Paper sheet
Objects First with Java
Teach A-Level Computer Science: Object-Oriented Programming in Python
Object-Oriented Programming
Object-Oriented PHP (1)
A Level Computer Science Topic 6: Introducing OOP
Presentation transcript:

Lilian Blot Announcements The TPOP problem class this afternoon:  group 1 should come at 3.30pm and group 2 at 4pm. Teaching Evaluation Form  week 9 practical session   good   bad Formative Assessment  week 10 during usual practical sessions  Tuesday at 16:30 & Wednesday at 11:30 bring your card Be on time, no entry accepted after the start of the assessment Autumn 2014 TPOP 1  

Lilian Blot OOP ANOTHER PROGRAMMING PARADIGM Object Oriented Programming Autumn 2014 TPOP 2

Lilian Blot Encapsulation as Information hiding Data belonging to one object is hidden from other objects. Know what an object can do, not how it does it. Information hiding increases the level of independence. Independence of modules is important for large systems and maintenance. Autumn 2014 TPOP 3

Lilian Blot Information Hiding f All Attributes are public Autumn 2014 TPOP 4 class Member: def __init__(self, firstname, surname, postcode, uid): self.firstname = firstname self.surname = surname self.postcode = postcode self.uid = uid self.borrowed = [] ## a list of items uid def __repr__(self): return ('<Member: uid = ' + str(self.uid) + ', ' + self.surname + ', ' + str(self.borrowed) + '>') Code No Information Hiding

Lilian Blot Private vs Protected vs Public Attributes Using the private modifier is the main way that an object encapsulates itself and hide data from the outside world. There is no completely private attributes in Python Private attributes can be simulated using two underscores for prefix  __attributename Protected attributes have a single underscore for prefix  _attributename No underscore prefix for public attributes Spring 2014 TPOP 5

Lilian Blot Private vs Protected vs Public Attributes If using private/protected attribute, you should provide adequate  Accessors method (read/get value)  Mutators method (change/set value) Which attribute must be public/protected/private is a design decision Which mutator/accessor to provide is also a design decision Spring 2014 TPOP 6

Lilian Blot Information Hiding f All Attributes are protected Autumn 2014 TPOP 7 class Member: def __init__(self, firstname, surname, postcode, uid): self._firstname = firstname self._surname = surname self._postcode = postcode self._uid = uid self._borrowed = [] ## a list of items uid def __repr__(self): return ('<Member: uid = ' + str(self._uid) + ', ' + self._surname + ', ' + str(self._borrowed) + '>') Code How to access Information?

Lilian Blot Defining Class Behaviour Methods, enable the behaviour of class instances. def methodName (self, ): Accessors are methods to read/access the values of some attributes Autumn 2014 TPOP 8 def getSurname(self): return self._surname def getUID(self): return self._uid Code Accessor

Lilian Blot Defining Class Behaviour Mutators are methods to set/modify the values of some attributes. We may want some attributes not to be modified by an external source (e.g. another class), so no mutator should be provided.  For example UID should never be changed (design decision) Autumn 2014 TPOP 9 def setSurname(self, name): self._surname = name Code Mutator

Lilian Blot Defining Class Behaviour How about modifying _borrowed attribute?  What are the drawbacks of this design? Use another design Autumn 2014 TPOP 10 def setBorrowed(self, borrowed): self._ borrowed = borrowed Code Mutator def addBorrowed(self, borrowed_item): if borrowed_item in self._borrowed: raise Exception(‘Already in borrowed’) else: self._ borrowed.append(borrowed_item) Def removeBorrowed(self, borrowed_item):... Code

Lilian Blot Method calls Internal method calls (inside class definition)  self.method_name(parameters) External method calls  object.method_name(parameters) Autumn 2014 TPOP 11 # Constructor Call of class QueueOOP lilian = Member(‘blot’,’lilian’,’yox xgh’, ‘01’) print ‘Surname is:', lilian.getSurname() Code External Method Call External method call (class Member)

Lilian Blot THE LIBRARY CLASS Class Design Autumn 2014 TPOP 12

Lilian Blot Code quality Two important concepts for quality of code: 1. Coupling 2. Cohesion Autumn 2014 TPOP 13

Lilian Blot Coupling Coupling refers to links between separate units of a program. If two classes depend closely on many details of each other, we say they are tightly coupled. We aim for loose coupling. Autumn 2014 TPOP 14

Lilian Blot Loose coupling Loose coupling makes it possible to:  understand one class without reading others;  change one class without affecting others.  Thus: improves maintainability. Autumn 2014 TPOP

Lilian Blot Cohesion Cohesion refers to the number and diversity of tasks that a single unit is responsible for. If each unit is responsible for one single logical task, we say it has high cohesion. Cohesion applies to classes and methods. We aim for high cohesion. Autumn 2014 TPOP 16

Lilian Blot High cohesion High cohesion makes it easier to:  understand what a class or method does;  use descriptive names;  reuse classes or methods. Autumn 2014 TPOP

Lilian Blot Cohesion of methods A method should be responsible for one and only one well defined task. Autumn 2014 TPOP

Lilian Blot Cohesion of classes Classes should represent one single, well defined entity. Autumn 2014 TPOP

Lilian Blot Last Week Practical Design Two dictionaries, one handling members and one handling items Both dictionaries strongly coupled, however they are not part of the same data structure Autumn 2014 TPOP 20 def add_member(firstname, surname, postcode, uid, listMembers): if uid in listMembers: ## uid already existing so must not add item return None else: member = Member(firstname, surname, postcode, uid) listMembers[uid] = member return member members = {} # keys are members UID, values are Member objects print 'Add member :', add_member('lilian','blot','xxx', '007', members) Code

Lilian Blot Design a Library Class Encapsulate the Items and Members into a third class Library  What are the attributes?  Should the attributes be public, protected, or private?  What are the Accessors?  What are the Mutators? To help in designing the class, think about a real world library:  what actions that can be done in a library? Autumn 2014 TPOP 21

Lilian Blot Summary By now, you should be able to:  create small scripts/program using selection and repetition  Decomposed complex problems into smaller sub-problems  Use Modularisation  Separation of concerns  Semantically coherent  Function  Classes/OOP  Write Documentation and use correct code style (conventions) Autumn 2014 TPOP 22