Designing applications 5.0. 2 Main concepts to be covered Discovering classes CRC cards Designing interfaces Patterns Objects First with Java - A Practical.

Slides:



Advertisements
Similar presentations
Comp1004: Object Oriented Design II Designing Applications Based on BlueJ Chapter 13.
Advertisements

COMP 121 Week 7: Object-Oriented Design and Efficiency of Algorithms.
Further abstraction techniques Abstract classes and interfaces 5.0.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
Introduction To System Analysis and Design
Objects First With Java A Practical Introduction Using BlueJ Designing object-oriented programs How to write code in a way that is easily understandable,
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 5: Restaurant.
Designing applications Software Engineering from a Code Perspective.
Fall 2007CS 225 Introduction to Software Design Chapter 1.
Object Oriented System Development with VB .NET
Objects First with Java A Practical Introduction using BlueJ
Lecture 4 Class Responsibility Collaboration Cards
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
Chapter 1 Software Development. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 1-2 Chapter Objectives Discuss the goals of software development.
1 Lecture 5 Introduction to Software Engineering Overview  What is Software Engineering  Software Engineering Issues  Waterfall Model  Waterfall Model.
Object-Orientated Design Unit 3: Objects and Classes Jin Sa.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
1 CS1001 Lecture Overview Object Oriented Design Object Oriented Design.
Further abstraction techniques Abstract classes and interfaces 3.0.
Spring 2009CS 225 Introduction to Software Design Chapter 1.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
The chapter will address the following questions:
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Introduction To System Analysis and design
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
Systems Analysis and Design in a Changing World, Fifth Edition
Design Patterns.
Introduction to Object-oriented programming and software development Lecture 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
CS 360 Lecture 3.  The software process is a structured set of activities required to develop a software system.  Fundamental Assumption:  Good software.
Big Java Chapter 12. Software Process - Waterfall Analysis Design Implementation Testing Deployment Does not work well when rigidly applied! established.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
12 Systems Analysis and Design in a Changing World, Fifth Edition.
Introduction to Software Design Chapter 1. Chapter Objectives  To become familiar with the software challenge and the software life cycle  To understand.
Objects First With Java A Practical Introduction Using BlueJ Designing applications 1.0.
Introduction To System Analysis and Design
Review: Cohesion and Coupling, Mutable, Inheritance Screen Layouts Software methodologies – Extreme Programming Object-Oriented Design – CRC Cards - UML.
Requirements as Usecases Capturing the REQUIREMENT ANALYSIS DESIGN IMPLEMENTATION TEST.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
1 What is OO Design? OO Design is a process of invention, where developers create the abstractions necessary to meet the system’s requirements OO Design.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
CIS 112 Exam Review. Exam Content 100 questions valued at 1 point each 100 questions valued at 1 point each 100 points total 100 points total 10 each.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
Designing applications Main concepts to be covered Discovering classes CRC cards Designing interfaces Patterns Objects First with Java - A Practical.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Chapter 17 – Object- Oriented Design. Chapter Goals To learn about the software life cycle To learn about the software life cycle To learn how to discover.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Design Reuse Earlier we have covered the re-usable Architectural Styles as design patterns for High-Level Design. At mid-level and low-level, design patterns.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 4 Slide 1 Software Processes.
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.
Software Development Process CS 360 Lecture 3. Software Process The software process is a structured set of activities required to develop a software.
1 COS 260 DAY 22 Tony Gauvin. 2 Agenda Questions? 9 th Mini Quiz corrected –Good results Assignment 5 Not corrected yet Assignment 6 Posted (one more)
Designing applications Main concepts to be covered Discovering classes CRC cards Designing interfaces Patterns © 2017 Pearson Education, Inc. Hoboken,
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Objects First with Java A Practical Introduction using BlueJ
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Introduction to Design Patterns
Reference: COS240 Syllabus
Further abstraction techniques
Chapter 8, Design Patterns Introduction
Presentation transcript:

Designing applications 5.0

2 Main concepts to be covered Discovering classes CRC cards Designing interfaces Patterns Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

3 Analysis and design How do we attack the analysis and design of a software system? A large and complex problem area with many different methodologies The verb/noun method is suitable for relatively small problems CRC cards support the initial design process Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

4 The verb/noun method Nouns in a description refer to things –Such as people, buildings, etc… –Corresponds to classes and objects Verbs refer to actions or behaviors –Such as writing, eating, etc… –Interactions between the objects –Corresponding to methods Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

5 A problem description Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling The cinema booking system should store seat bookings for multiple theaters. Each theater has seats arranged in rows. Customers can reserve seats and are given a row number and seat number. They may request bookings of several adjoining seats. Each booking is for a particular show (i.e. the screening of a given movie at a certain time). Shows are at an assigned date and time, and scheduled in a theater where they are screened. The system stores the customer’s phone number. What nouns and verbs can you identify in this example?

6 A problem description Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling The cinema booking system should store seat bookings for multiple theaters. Each theater has seats arranged in rows. Customers can reserve seats and are given a row number and seat number. They may request bookings of several adjoining seats. Each booking is for a particular show (i.e. the screening of a given movie at a certain time). Shows are at an assigned date and time, and scheduled in a theater where they are screened. The system stores the customer’s phone number. How are the nouns and verbs related?

7 Nouns and verbs Objects First with Java - A Practical Introduction using BlueJ, © David J. Barneads, Michael Kölling Cinema booking system Stores (seat bookings) Stores (phone number) Seat booking Theater Has (seats) Seat Row Customer Reserves (seats) Is given (row number, seat number) Requests (seat booking) Row number Seat numberShow Is scheduled (in theater) Movie DateTime Telephone number At first, use EACH noun as a class … even “bad” ones ALL nouns are represented as a singular class name Multiplicity is achieved with multiple instance objects

8 Using CRC cards Class – Responsibilities - Collaborators Use one index card to represent each class (important here to use real, physical cards) Each index card records: –The class name –The class’s responsibilities –The class’s collaborators (classes that this one uses) Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

9 A CRC card Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Class name Collaborators Responsibilities

10 Scenarios The classes are approximated with a physical representation by the CRC cards Use scenarios to figure out necessary interactions between our classes Each scenario is an example of an activity that the system has to carry out or support –Sometimes known as use cases Used to discover and record object interactions (collaborations) Scenarios performed best through a group –Each person assigned one class –Plays role by saying what that class is doing –During the scenario, responsibilities and collaborators are recorded on the CRC card Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

11 Scenario example A customer calls the cinema and wants to make a reservation for two seats tonight to watch the classic movie The Shawshank Redemption. The cinema employee starts using the booking system to find and reserve a seat.  User finds all Shawshank Redemption showings for tonight o CinemaBookingSystem responsibility: Can find shows by title and day. o CinemaBookingSystem collaborator: Show  How does system find the show? Who does it ask? In a collection o CinemaBookingSystem responsibility: Stores collection of shows. o CinemaBookingSystem collaborator: Collection (of Shows)  System retrieves & displays a detailed show list for user to give choices o CinemaBookingSystem responsibility: Retrieves and displays show details. o Show responsibility: Provides details about theater and number of free seats.  Assume customer chooses specific seats and user makes reservation o CinemaBookingSystem responsibility: Accepts seat reservations from user.  Seat reservation task for particular show is delegated to Show class o Show responsibility: Can reserve seat.  Show stores seat reservations with link to a Theater object o Show responsibility & collaborator: Stores theater. & Theater  Theater makes a seat reservation in a collection of seats or row-seats? o Theater responsibility & collaborator : Stores rows. & Row o Row responsibility & collaborator : Stores collection of seats. & Seat o Row responsibility: Accepts reservation request for seat. o Row responsibility: Can find seats by number. o Seat responsibility: Accepts reservation. & Stores reservation status.

12 A partial example Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling CinemaBookingSystem Collaborators Can find shows by title and day. Show Stores collection of shows. Collection Retrieves and displays show details. Accepts seat reservations from user....

13 Multiple scenarios necessary Scenarios dealing with user and customer requests: Customer requests 5 seats together Customer requires lookup of forgotten seat numbers Customer cancels with only his name and show Customer wants additional seats near existing seats Cancelled show and all customers need to be called Scenarios dealing with user and customer requests: New cinema setup with multiple theaters in varying sizes of rows and seats New movie scheduled at various times and dates in a particular theater Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

14 Scenarios as analysis Helps check that the problem description is clear and complete Sufficient time should be taken to execute as many scenarios as possible Ensure every detail is recorded No shortcuts should be taken! The analysis will lead into design –Spotting errors or omissions here will save considerable wasted effort later Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

15 Class design Scenario analysis helps to clarify the application structure –Each card maps to a class –Collaborations reveal class cooperation and object interaction Responsibilities reveal public methods –Sometimes instance fields –e.g. “Stores collection...” Class responsibilities should be evaluated using good design principles –Responsibility-driven design –Coupling –Cohesion

16 Designing class interfaces Replay scenarios in terms of method calls, parameters and return values Note the resulting method signatures & instance fields this time (new cards) Create outline classes with method stubs (empty body) for all public methods ◦Seems tedious but is very valuable Careful design is a key to successful implementation Code mistakes can usually be fixed fairly easily later, BUT … design mistakes can be very expensive, fatal or even unfixable Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

17 Documentation Write class comments Write method comments Describe the overall purpose of each Documenting now ensures that: –The focus is on what rather than how –That it doesn’t get forgotten! In real-life applications, a good programmer understands that documentation focusing on what a class/method does is just as important as its implementation. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

18 Cooperation Team-working is likely to be the norm not the exception Documentation is absolutely essential for team working Clean object-oriented design with loosely-coupled components supports cooperation Initial design best done in a group Then separation of classes may be implemented independently Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

19 Prototyping Supports early investigation of a system –Early problem identification Incomplete components can be simulated –e.g. always returning a fixed result –Avoids random behavior which is difficult to reproduce Useful with team development –Continuation of development and testing when not all classes are completed Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

20 Several models to build software Waterfall model Traditional & conservative with widespread use No looking back approach with work on current and previous phases Fixed sequence of several phases –Analysis of the problem –Design of the software –Implementation of components –Unit testing –Integration testing –Delivery of system to the client Flaws causing problems with this model –Assumes developers fully understand system’s functionality –Assumes that the system does not change after delivery No provision for iteration

21 Iterative development Addressing problems with waterfall Use early prototyping to give impressions Frequent client interaction & feedback Iterate several times thru the cycle: –Analysis –Design –Prototype implementation –Client feedback Growth model A growth model is the most realistic: –Design/implement a small, clean system –Add additional features gradually (grow it) –Deliver usable systems repeatedly/frequently –Notion of a complete system does NOT exist! Some tasks & skills become more important –Software maintenance –Code reading –Designing for extendibility –Documentation –Coding for understandability

22 Using design patterns Inter-class relationships are important and can be complex Some relationships recur in different applications Design patterns help clarify relationships and promote reuse –Describes a common problem that occurs regularly in software development –Then describes a general solution that can be used in many different contexts o Typically description of a small set of classes and their interactions Helps our task by providing: –Good, reusable solutions (in class structure, not code) –Established, common vocabulary for team designing Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

23 Pattern structure Template for design patterns Pattern name Problem addressed and split into: –Intent, motivation and applicability Solution description listing: –Structures, participants, and collaborations Consequences of usage: –Results and trade-offs Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

24 Decorator Augments functionality of an existing object to respond to the same methods & additional ones Decorator object wraps another object –Decorator usually has a similar interface –Clients now interact with Decorator instead of original –Decorator will now: o … pass the method call to the enclosed object o … but the decorator may also perform additional actions Example: java.io.BufferedReader –Wraps and augments an unbuffered Reader object – BufferedReader implements the same interface –Can be used instead of Reader –Adds to basic behavior of Reader

25 Singleton Ensures only a single instance of a class exists with unified access to it –All clients use the same object –i.e. IDE has only 1 compiler or 1 debugger Private constructor prevents external instantiation –Ensures no outside calls to it –Client classes can not create new instances An instance obtained via static getInstance() Parser parser = Parser.getInstance(); public class Parser { private static Parser instance = new Parser(); public static Parser getInstance() { return instance; } private Parser() { … }

26 Factory method Provides the interface for creating objects, but allows subclasses to decide which specific class Clients expect superclass or dynamic type interface A factory method is free to return an implementing-class object or subclass object Exact type returned depends on context Example: iterator methods of collection classes –Client deals with objects of type Collection & Iterator –In reality, dynamic type of collection (maybe ArrayList) returns an ArrayListIterator when iterator method is called Factory method specialized in subclasses tor return specialized instances to the official return type. public void process(Collection collection) { Iterator it = collection.iterator(); … }

27 Observer Supports separation of internal model from a view of that model ( i.e. GUI ) Observer defines a one-to-many relationship between objects –Object-observed notifies all Observers of any state change –Achieved with a low degree of coupling between them –Allows for multiple views (alternatives or simultaneously) Example: foxes-and-rabbits SimulatorView –Presented populations on screen as 2D animated grid –Other possibilities include timeline graph and bar chart

28 Observer pattern structure Observable entity ( i.e. Field) extends Observable Observer ( i.e. SimulatorViewer) implements Observer –Provides methods for observers to attach themselves to the observed entity –Ensures that observers’ update method called when observed entity invokes its inherited notify method –Actual observers then get updated state from field to redisplay Uses Observable & Observer classes

29 Review Class collaborations and object interactions must be identified –CRC analysis supports this An iterative approach to design, analysis and implementation can be beneficial –Regard software systems as entities that will grow and evolve over time Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

30 Review Work in a way that facilitates collaboration with others Design flexible, extendible class structures –Being aware of existing design patterns will help you to do this Continue to learn from your own and others’ experiences Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling