CSSE 220 Day 17 Introduction to your Vector Graphics project

Slides:



Advertisements
Similar presentations
Chapter 8: Designing Classes
Advertisements

Designing Classes Chapter 8. Classes Collection of objects Objects are not actions Class names – Nouns Method names – Verbs What Makes a Good Class Represent.
Chapter 8 – Interfaces and Polymorphism Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Inheritance Inheritance Reserved word protected Reserved word super
Chapter 8 Designing Classes. Assignment Chapter 9 Review Exercises (Written)  R8.1 – 8.3, 8.5 – 8.7, 8. 10, 8.11, 8.13, 8.15, 8.19, 8.20 Due Friday,
Chapter Goals To learn how to choose appropriate classes to implement
Chapter 7 Designing Classes Goals  To learn how to choose appropriate classes to implement  To understand the concepts of cohesion and coupling  To.
CSM-Java Programming-I Spring,2005 Class Design Lesson - 4.
Interfaces. Lecture Objectives To learn about interfaces To be able to convert between class and interface references To appreciate how interfaces can.
Class Design CSC 171 FALL 2004 LECTURE 11. READING Read Chapter 7 It’s abstract But it should help with project #1.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Computer Science A 8: 6/3. Group data in an object class PlayerData{ String name; int score; }.. PlayerData d=new PlayerData(); d.name=“Mads”; d.score=100;
Chapter 9 – Designing Classes. Chapter Goals  Learn to identify side effects  Know when to use method preconditions and postconditions  Go in depth.
CSS446 Spring 2014 Nan Wang.  To learn how to choose appropriate classes for a given problem  To understand the concept of cohesion  To minimize dependencies.
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
Packages. Package A package is a set of related classes Syntax to put a class into a package: package ; public class { …} Two rules:  A package declaration.
CS 350 – Software Design The Object Paradigm – Chapter 1 If you were tasked to write code to access a description of shapes that were stored in a database.
Week 12 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Introduction to Object Oriented Design Version 1.1.
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A class represents a single concept from the problem domain Name.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 8 – Designing Classes.
Review: Cohesion and Coupling, Mutable, Inheritance Screen Layouts Software methodologies – Extreme Programming Object-Oriented Design – CRC Cards - UML.
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
Chapter 9 Interfaces and Polymorphism. Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A class represents a single concept from the problem domain, or a.
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.
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
12 OBJECT-ORIENTED DESIGN CHAPTER
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Objects and Classes.
UML Part 1: Class Diagrams. Introduction UML stands for Unified Modeling Language. It represents a unification of the concepts and notations presented.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Chapter 9 – Designing Classes Goals Learning to design classes Learning to design classes Preconditions and postconditions for methods Preconditions.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Chapter 7 Designing Classes. Chapter Goals  To learn how to choose appropriate classes to implement  To understand the concepts of cohesion and coupling.
Fall 2006Adapded from Java Concepts Slides1 Designing Classes Advanced Programming ICOM 4015 Lecture 8 Reading: Java Concepts Chapter 8.
Chapter 9 – Designing Classes. Chapter Goals Discovering and learning to Design classes Discovering and learning to Design classes Preconditions and postconditions.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Chapter 1 Overview of UML for Java Programmers. 2 Outline Diagram Types Diagram Types Class Diagrams Class Diagrams Object Diagrams Object Diagrams Sequence.
AP CSP: Cleaning Data & Creating Summary Tables
Strategies That Support Differentiated Processing
Building Java Programs
AP CSP: Data Assumptions & Good and Bad Data Visualizations
Introduction to Eclipse
Chapter 8 Designing Classes
Recall The Team Skills Analyzing the Problem (with 5 steps)
Use Case Model.
Lecture 7 Designing Classes
Strategies That Support Differentiated Processing
Object Oriented Programming
Classes and Objects 2nd Lecture
Problem Solving (design of programs) CS140: Introduction to Computing 1 8/26/13.
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
Classes and Objects: Encapsulation
Classes and Objects Encapsulation
Introductory Workshop THE CDIO APPROACH TO ENGINEERING EDUCATION
Chapter 6 Class Definitions and Member Functions
Personalize Practice with Accelerated Math
Informatics 122 Software Design II
Introduction to Objects
CISC/CMPE320 - Prof. McLeod
Object Oriented Programming Review
Year 11 GCSE Revision.
OO Programming Concepts
Agenda Warmup Lesson 2.2 (parameters, etc)
CMSC 202 Encapsulation Version 9/10.
Software Specifications
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

CSSE 220 Day 17 Introduction to your Vector Graphics project SwingDemo continued Designing classes Screen Layout sketch for VG Bring : Handout for Pair Programming In-class Quizzes (No in-class quiz today) These Slides Schedule for today Attendance PIN:

VectorGraphics project Visit http://www.rose- hulman.edu/class/csse/csse220/current/Projects/VectorGraphics/teams.html And find your teammates. Sit with them. Introduce yourselves:

With your teammates, continue your SwingDemo project, helping everyone reach the same point in the project (pair program, with the teammates furthest along being the observer)

What is good object-oriented design? It starts with good classes…

Good Classes Typically Often come from nouns in the problem description May… Represent single concepts Circle, Investment Be abstractions of real-life entities BankAccount, TicTacToeBoard Be actors Scanner, CircleViewer Be utilities Math Discuss why the ‘er’s are highlighted for actors: actors == do-ers Q2

What Stinks? Bad Class Smells Can’t tell what it does from its name PayCheckProgram Turning a single action into a class ComputePaycheck Name isn’t a noun Interpolate, Spend Q3

Analyzing Quality of Class Design Cohesion Coupling [outline slide]

Cohesion A class should represent a single concept Public methods and constants should be cohesive Which is more cohesive? CashRegister double NICKEL_VALUE double DIME_VALUE double QUARTER_VALUE void add(int nickels, int dimes, int quarters) … CashRegister void add(ArrayList<Coin> coins) … Coin double getValue() Q4

Dependency Relationship When one classes requires another class to do its job, the first class depends on the second Shown on UML diagrams as: dashed line with open arrowhead CashRegister void add(ArrayList<Coin> coins) … Note CashRegister depends on Coin But Coin does NOT depend on CashRegister Coin double getValue() Q5

Coupling Lots of dependencies == high coupling Few dependencies == low coupling Which is better? Why? Low coupling  less brittle, can change one class without changing the others; can reason about one class without thinking about many others. Q6

Quality Class Designs High cohesion Low coupling

Accessors and Mutators Review Accessor method: accesses information without changing any Mutator method: modifies the object on which it is invoked [Ask for examples of each that we’ve used] Q7

Immutable Classes Accessor methods are very predictable Easy to reason about! Immutable classes: Have only accessor methods No mutators Examples: String, Double Is Rectangle immutable?

Immutable Class Benefits Easier to reason about, less to go wrong Can pass around instances “fearlessly” A: Don’t have to worry about some other code changing “our” object. Q8

Avoid this if you can! Document it if you can’t Side Effects Side effect: any modification of data Method side effect: any modification of data visible outside the method Mutator methods: side effect on implicit parameter Can also have side effects on other parameters: public void transfer(double amt, Account other) { this.balance -= amt; other.balance += amt; } What are the side effects in the code snippet? Why would we want to avoid side effects on other parameters? (surprising to the caller. Be sure to document well.) Avoid this if you can! Document it if you can’t

Documenting Side Effects /** * Transfers the given amount from this * account to the other account. Mutates * this account and other. * * @param amt * amount to be transferred * @param other * receiving account (mutated) */ public void transfer(double amt, Account other) { this.balance -= amt; other.balance += amt; } [[[Inserted to clear up muddiness from last time. Drop this slide if you fix session 13.]]]

Class Design Exercise Suppose you were going to implement a program to let two people play chess against each other. Think about what classes you would need. (Search on-line to find the rules of chess if you aren’t familiar with the game.) List all the classes that you can think of that might be useful in implementing your program. For now you can assume that users will enter moves in the console, but you’ll display the board in a graphics window.

Class design exercise From your list of potential classes, decide which ones you would use in an actual implementation. Pay particular attention to the rules for good classes that we discussed in class. Sketch a UML class diagram for these classes. Show the public interface (including the arguments of the methods) of each class and the dependency relationships between the classes. Recall that dependency relationships are indicated by dashed lines with open arrow heads. Write a couple of paragraphs explaining why you chose the classes that you did for your design. Discuss the cohesion and coupling of your classes.

Vector Graphics Show movie See features in instructions Make a Screen Layout sketch, per instructions