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

Slides:



Advertisements
Similar presentations
Chapter 25 Lists, Stacks, Queues, and Priority Queues
Advertisements

Advanced Piloting Cruise Plot.
Final and Abstract Classes
Chapter 1: The Database Environment
Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 7 System Models.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
18 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Introduction to Web Services.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
State Machines March 18, Compositional Systems | Summary Composition is a powerful way to build complex systems. PCAP framework to manage complexity.
Lilian Blot TO PROGRAMMING & PYTHON Introduction Autumn 2012 TPOP 1.
COMP171 Fall 2005 Lists.
Linked Lists Chapter 4.
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Linear Lists – Linked List Representation
Data Structures: A Pseudocode Approach with C
Data Structures ADT List
Chapter 24 Lists, Stacks, and Queues
ITEC200 Week04 Lists and the Collection Interface.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
ADTs unsorted List and Sorted List
Data Structures Using C++
FIFO Queues CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
ABC Technology Project
Lilian Blot Recursion Autumn 2012 TPOP 1. Lilian Blot Recursion Autumn 2012 TPOP 2.
Lilian Blot CORE ELEMENTS PART I Python Language Autumn 2013 TPOP 1.
VOORBLAD.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
0 Teams: Roles of Group Members. 1 What is a team? Two or more people ……….
Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
Lilian Blot PART III: ITERATIONS Core Elements Autumn 2012 TPOP 1.
© 2012 National Heart Foundation of Australia. Slide 2.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 27 Slide 1 Quality Management.
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
Lecture 6: Software Design (Part I)
Lilian Blot PART V: FUNCTIONS Core elements Autumn 2013 TPOP 1.
25 seconds left…...
Chapter 9: Data Structures I
Week 1.
Lilian Blot CORE ELEMENTS SELECTION & FUNCTIONS Lecture 3 Autumn 2014 TPOP 1.
We will resume in: 25 Minutes.
Module 12 WSP quality assurance tool 1. Module 12 WSP quality assurance tool Session structure Introduction About the tool Using the tool Supporting materials.
Lilian Blot CORE ELEMENTS PART V: FUNCTIONS PARAMETERS & VARIABLES SCOPE Lecture 5 Autumn 2014 TPOP 1.
Stack & Queues COP 3502.
Chapter 11 Component-Level Design
Foundations of Data Structures Practical Session #7 AVL Trees 2.
Modeling Main issues: What do we want to build How do we write this down.
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
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.
Lilian Blot LINEAR DATA STRUCTURE LINKED LIST Abstract Data Structure Autumn 2014 TPOP 1.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Lilian Blot INHERITANCE Object Oriented Programming Spring 2014 TPOP 1.
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.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
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.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 6.0.
Stack ADT & Modularity 2 implementations of the Stack abstract data type: Array Linked List Program design: modularity, abstraction and information hiding.
Presentation transcript:

Lilian Blot Announcements Teaching Evaluation Form week 9 practical session Formative Assessment week 10 during usual practical sessions group 1 Friday at 11:30 group 2 Wednesday at 9:30 bring your card Autumn 2013 TPOP 1

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

Lilian Blot Last Week: ADT implementation see code: Linked_Queue_struct_Answer.py Autumn 2012 TPOP 3

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 2013 TPOP 4

Lilian Blot What are Classes? Classes are composed from structural and behavioural constituents. Data field members (member variables or instance variables) enable a class instance to maintain state. a.k.a properties, fields, data members, or attributes Methods, enable the behaviour of class instances. Classes define the type of their instances Autumn 2013 TPOP 5

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

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 2013 TPOP 7

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 2013 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 2013 TPOP 9

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 2013 TPOP

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

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

Lilian Blot PART II: IMPLEMENTATION Object Oriented Programming Autumn 2013 TPOP 13

Lilian Blot Python and OOP Modules Classes : class keyword Attributes Methods: __repr__(self) for example Constructor: __init__(self,…) Autumn 2013 TPOP 14

Lilian Blot Towards OOP f Autumn 2013 TPOP 15 class QueueOOP: def __init__(self): self._head = None ## Pointer to front of queue, _Node object self._tail = None ## Pointer to back of the queue, _Node object self._size = 0 def dequeue(self):… def enqueue(self,element):… def isempty(self):… def size(self):… Code OOP class LinkedQueue: def __init__(self, element): self.head = None ## Pointer to front of queue self.tail = None ## Pointer to back of the queue self.size = 0 Code Procedural

Lilian Blot Towards OOP Autumn 2013 TPOP 16 def dequeue(queue): if queue.size == 0: raise IndexError('dequeue from empty queue') else: ## remove first element, the head element = queue.head.datum queue.head = queue.head.next if queue.head is None: queue.tail = None queue.size -= 1 return element Code Procedural def dequeue(self): if self.isempty(): raise IndexError('dequeue from empty queue') else: ## remove first element, the head element = self._head.datum self._head = self._head.next if self._head is None: self._tail = None self._size -= 1 return element Code OOP Internal method call

Lilian Blot Method calls Internal method calls (inside class definition) self.method_name(parameters) External method calls object.method_name(parameters) Autumn 2013 TPOP 17 queue = QueueOOP() # Constructor Call of class QueueOOP queue.enqueue(1) queue.enqueue(3) print 'dequeued element is:', queue.dequeue() print 'size is:', queue.size() Code External Method Call External method call (class QueueOOP)

Lilian Blot Code quality Two important concepts for quality of code: 1. Low Coupling 2. High Cohesion Autumn 2013 TPOP 18

Lilian Blot Low Coupling f Autumn 2013 TPOP 19 class QueueOOP: def __init__(self): self._data = [] ## list object containing all element in queue def dequeue(self):… def enqueue(self,element):… Code OOP second implementation class QueueOOP : def __init__(self, element): self._head = None ## Pointer to front of queue self._tail = None ## Pointer to back of the queue self._size = 0 def dequeue(self):… def enqueue(self,element):… Code OOP first implementation

Lilian Blot Low Coupling Autumn 2013 TPOP 20 def dequeue(self): if self.isempty()== 0: raise IndexError('dequeue from empty queue') else: ## remove first element, the head element = self._head.getElement() self._head = self._head.next() self._size -= 1 return element Code OOP first implementation def dequeue(self): if self.isempty()== 0: raise IndexError('dequeue from empty queue') else: ## remove and return first element return self._data.pop() Code OOP second implementation

Lilian Blot Low Coupling Autumn 2013 TPOP 21 queue = QueueOOP() # Constructor Call of class QueueOOP queue.enqueue(1) queue.enqueue(3) print 'dequeued element is:', queue.dequeue() print 'size is:', queue.size() Code Using QueueOOP The use of QueueOOP is independent of implementation The change of implementation does not have an impact on the program using the ADT.

Lilian Blot High Cohesion Autumn 2013 TPOP 22 The class QueueOOP contains only method necessary for this type of ADT. does NOT implement add_first, insert_at, remove, etc. If the user need such methods, he/she must use a different ADT (not a queue). Several ADTs could/should be implemented in the same module

Lilian Blot Writing class documentation Your own classes should be documented the same way library classes are. Other people should be able to use your class without reading the implementation. Make your class a 'library class'! Autumn 2013 TPOP 23

Lilian Blot Elements of documentation Documentation for a class should include: the class name a comment describing the overall purpose and characteristics of the class a version number the authors names documentation for the constructor and each method Autumn 2013 TPOP 24

Lilian Blot Elements of documentation The documentation for each constructor and method should include: the name of the method the return type (if known) the parameter names and types (if needed) a description of the purpose and function of the method a description of each parameter a description of the value returned Autumn 2013 TPOP 25

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 Handle Abstract Data Type Write Documentation and use correct code style (conventions) Autumn 2013 TPOP 26

Lilian Blot Exercises Rewrite Your Queue and Deque ADT using OOP You can use practical 6 model answers Rewrite the Library, Member and Item classes from practical 5 if you havent done so, you should create one class for the library, one for members and one for items Low Coupling: separate user interface and core of the program (e.g. adding members to library, borrowing items,…) use separate files, one containing the three classes Library, Member, Item, and one for the User Interface (reading inputs from users) Autumn 2013 TPOP 27