Computer Science Victoria University of Wellington Copyright: david streader, Victoria University of Wellington Simple Design COMP 112 2016.

Slides:



Advertisements
Similar presentations
Revealing the Secrets of Self-Documenting Code Svetlin Nakov Telerik Corporation For C# Developers.
Advertisements

Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
MiniDraw Testing COMP 102 # T1
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Creating and using Objects.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Recursion COMP T1.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington UML for design: Class Diagrams.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Interface COMP T1.
Abstract Data Types (ADTs) An ADT consists of: –a set of values, and –a set of operations on those values. Example: rational numbers –some values: 15/7,
Software Engineering and Design Principles Chapter 1.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Department of Computer Science University of Maryland, College Park
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Objects Real and Java COMP.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Introduction to Object-oriented Programming CSIS 3701: Advanced Object Oriented Programming.
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.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
Computer Science Victoria University of Wellington Copyright: david streader, Victoria University of Wellington Simple Design COMP
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington GUI and the UI API COMP.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington While loops and the UI API.
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 21.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Recursion COMP 102 # T1.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Arrays and ArrayLists.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington ArraySet and Binary Search.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
SE: CHAPTER 7 Writing The Program
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Cohesion and Coupling CS 4311
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
1 CSC 222: Object-Oriented Programming Spring 2013 Course goals:  To know and use basic Java programming constructs for object- oriented problem solving.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Networking and Concurrency COMP.
David Streader & Peter Andreae Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Objects.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Introduction to Software Architecture.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Recursion COMP 103 #
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Copyright 2007, Information Builders. Slide 1 iWay Web Services and WebFOCUS Consumption Michael Florkowski Information Builders.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Recursion COMP T1.
Dale Roberts Object Oriented Programming using Java - Getters and Setters Dale Roberts, Lecturer Computer Science, IUPUI
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Mapping Designs to Code. It specify how to map the design into object oriented language The UML artifacts created during the design work, the interaction.
Recursion COMP T1 #6.
CSC 222: Object-Oriented Programming
CSC 222: Object-Oriented Programming
Algorithms and Problem Solving
CSC 222: Computer Programming II
Software Correctness Indexed Processes SWEN T2.
Interface Java 7 COMP T1.
Chapter 3: Using Methods, Classes, and Objects
CSC 222: Object-Oriented Programming
Component-Level Design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Presentation transcript:

Computer Science Victoria University of Wellington Copyright: david streader, Victoria University of Wellington Simple Design COMP

© Peter Andreae COMP 112 :2 Outline Design is essential and informal and should be easy for customers to relate to. 1.Design for the moment and refactor Agile approach Do not guess the future just code for now – requires extensive executable tests to allow easy refactoring 2.Design for the future Traditional approach Code to subsequently make likely amendments easy to implement

© Peter Andreae COMP 112 :3 Customer language High level structure should be understandable with out reading all the detail. High level structure to reflect Customers language Design and protocol stacks! Design a stack of “models” a model at one layer of abstraction is implemented on the model beneath it. The model at each layer in the stack should be understandable on its own. Ideally you do not want the details in the lower layers to appear in at the layer you are working on.

© Peter Andreae COMP 112 :4 Private data Public Customers Data is private but access to the data is public Thus customers talk more abstractly then programmers As a part of a large algorithm a customer wants to: get the cost of item with known id. A programmer knows that the inventory of items is held in an ArrayList So a part of the large algorithm becomes: …….. for(Item p: inv){ if (p.getID() == id) { c = p.getCost(); break; } } ……

© Peter Andreae COMP 112 :5 How can you do better To the customer “get the cost of item with know id” is an atomic action. Can we design code to reflect this? Wrapper classes can hide data structures and provide functionality

© Peter Andreae COMP 112 :6 Define an inventory Interface If you want to hide implementation details define an interface The designer of the inventory can change the implementation details from an ArrayList to an array or …. And the programmers using the inventory will not have to change thir code!

© Peter Andreae COMP 112 :7 Why is this better! When the high level structure of your code reflect the customers world view then: By talking to the customer you can debug your design. Changes, described by the customer, are more easy to make. The basic customer concepts are often repeated in different situations over and over again. Hence less code duplication should result. Changing the underlying data structure e.g. from an ArrayList to a data base, only requires changing how the interface implements the interface.

© Peter Andreae COMP 112 :8 Design Questions How to change the design so that the inventory can hold different sorts of Parts. Some Parts have a best before date some do not Some Parts have methods to look up the, ever changing, ethical standards of their country of origin. Some do not.

© Peter Andreae COMP 112 :9 Some OO design principles DRY – Do not Repeat Yourself A class should do one thing and do it well Data encapsulation: means more than make fields private

© Peter Andreae COMP 112 :10 Objects as parameters When you pass an object as a parameter you are passing both data and code. Calling a method can: 1.Return a value 2.Change the state of the object 3.Interact with the environment Pure methods do not change the state of the object. Pure methods are functions mapping the parameters input to the value returned. An Object with one pure method is just like a function.

© Peter Andreae COMP 112 :11 Pass Functions in place of Objects A Predicate provides a function test from some domain (here Items) and returns a Boolean A Consumer provides a function accept from some domain and returns nothing (+side effect). Predicate is predefined - any one method object will work. Next we use lambdas when we call printSome Predicate is an Interface with one method test(Item i)

© Peter Andreae COMP 112 :12 Functions - Lambdas In place of defining an object with one method you can define a function in java: “ -> ” Examples p -> p.getID p -> p.getID == x z -> z.print() Lambdas can be used in place of an object with one method. Lambdas offer no new functionality but are shorter to code and easier to understand.

© Peter Andreae COMP 112 :13 Passing function not Objects Even though lambdas add no new functionality to Java because we are all lazy the easy of coding with lambdas changes how we code and even how we design!

© Peter Andreae COMP 112 :14 Stateless programming Functional programming : programming with functions : methods without side effects. Use functional language Use Java with streams and lambdas For example: int sum = wdts.stream().filter(b -> b.getColor() == RED).mapToInt(b ->b.getWeight()).sum(); Here we use widgets, a Collection, as a source for a stream. Are Java Lambdas Pure?

© Peter Andreae COMP 112 :15 Simple Design Metaphors Make your high level design closely reflect the language of the customer – domain expert. Use stateless programming to reduce side effects and hence errors. Custom build your own metaphor for the problem at hand Protocol stack Client Server Divide and conquer To do lists … The more clearly you understand the problem the easier it is to construct a good architecture for your code