Copyright by Scott GrissomCh 7 Designing Classes Slide 1 Well Designed Classes (Ch 7) Applications are a collection of interacting classes Our Goal It.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Lesson-06 Designing classes
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Object Orientated Concepts. Overview  The world is objects  Defining an object  Not a function, it’s a method  Lets inherit want we can  Objects.
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,
Copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 1 Java Class Library a very large collection of classes for you to use as needed the challenge.
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.
Georgia Institute of Technology Making Text for the Web part 4 Barb Ericson Georgia Institute of Technology March 2006.
Copyright 2008 by Pearson Education Building Java Programs Chapter 7 Lecture 27: More on ArrayList, Reference Semantics Command Line Arguments reading:
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.
OOP (Java) 7. Good Class Design Objectives
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 3.0.
1 CSC 222: Object-Oriented Programming Spring 2012 Object-oriented design  example: word frequencies w/ parallel lists  exception handling  System.out.format.
Observer Behavioral Pattern. Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified.
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
Programming in C# Observer Design Pattern
Parameters. Overview A Reminder Why Parameters are Needed How Parameters Work Value Parameters Reference Parameters Out Parameters.
Chapter 7 Object-Oriented Design Concepts
Designing Classes 2 How to write classes in a way that they are easily understandable, maintainable and reusable.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Case study Students. Array of objects Arrays can hold objects (ref to objects!) Each cell in an array of objects is null by default Sample: from student.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
2-Dec-15 Inner Classes By Alguien Soy. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside.
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
M1G Introduction to Programming 2 5. Completing the program.
12 OBJECT-ORIENTED DESIGN CHAPTER
CS 210 Final Review November 28, CS 210 Adapter Pattern.
The Strategy Pattern SE-2811 Dr. Mark L. Hornick 1.
1 COS 260 DAY 14 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz graded  Oct 29 –Chapter 6 Assignment 4 will be posted later Today –First two problems.
Building Your Own Class. We will build a simple instance class for an inventory control application and a main program to test it. We need an Item class.
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
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.
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
STATICS /. When static?? When a method’s behaviors has no dependency on state of an object i.e.., when the method will never be instance specific. E.g..,
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 6.0.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Objektorienterad programmering d2, förel. 8
CompSci 280 S Introduction to Software Development
CSC 222: Object-Oriented Programming Spring 2017
using System; namespace Demo01 { class Program
Coupling and Cohesion 1.
Conception OBJET GRASP Patterns
Data Abstraction: The Walls
Objects First with Java
Writing Methods.
Objects First with Java
Inner Classes 29-Nov-18.
class PrintOnetoTen { public static void main(String args[]) {
Objektorienterad programmering d2, förel. 8
COS 260 DAY 14 Tony Gauvin.
CSC 222: Object-Oriented Programming Spring 2013
Java Coding 4 (part2) David Davenport Computer Eng. Dept.,
Inner Classes 1-May-19.
Java Looking at our first console application in Eclipse
CSC 222: Object-Oriented Programming Spring 2012
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
ITE “A” GROUP 2 ENCAPSULATION.
Presentation transcript:

copyright by Scott GrissomCh 7 Designing Classes Slide 1 Well Designed Classes (Ch 7) Applications are a collection of interacting classes Our Goal It works correctly Additional Goals Easy to read Easy to reuse Easy to maintain Easy to extend Also known as “elegant code”

copyright by Scott GrissomCh 7 Designing Classes Slide 2 Cohesion (7.11) the number of operations or tasks contained in a single entity Methods should do one, and only one, task This makes them short Easy to understand Easier to reuse Classes model well defined single entities Avoid low cohesion Strive for high cohesion

copyright by Scott GrissomCh 7 Designing Classes Slide 3 Coupling (7.6) the interconnectedness of classes classes should be independent and not rely too heavily on other classes Changes to code in one class should have minimal impact on other classes Avoid tight coupling Strive for loose coupling

copyright by Scott GrissomCh 7 Designing Classes Slide 4 World of Zuul Start with a demo Game Room Parser Command CommandWords Provide students with the code for Game and Room

copyright by Scott GrissomCh 7 Designing Classes Slide 5 Avoid code duplication (7.4) Place duplicate code into a method Notice the duplicate code in Game class This is low cohesion create a new method to handle the code (high cohesion) printLocationInfo() page 197

copyright by Scott GrissomCh 7 Designing Classes Slide 6 Decouple Code (7.5) Game knows too much about Room Improve Room class make instance variables private create getExit(direction) method nextRoom = currentRoom.getExit(“north”); Modify Game class update createRooms() update printWelcome() update goRoom() Room and Game are too tightly coupled

copyright by Scott GrissomCh 7 Designing Classes Slide 7 Extending the design (7.5) What if we want additional directions such as UP and DOWN? How much code do we have to change? add hashmap to Room to allow for an unlimited number of directions update setExits()

copyright by Scott GrissomCh 7 Designing Classes Slide 8 Responsibility Driven Design 7.7 Room should be responsible for generating the exit String, not Game String getExitString() update getLongDescription() update the Game class

copyright by Scott GrissomCh 7 Designing Classes Slide 9 More Low Cohesion (7.10) Who should list the commands in help? Probably Parser. String getCommandList() Good design tip: strive to have all printing to the screen occur in one class

copyright by Scott GrissomCh 7 Designing Classes Slide 10 More Zuul Project 7.11 discusses an Item class 7.12 discusses a Player class 7.13 should be skipped

copyright by Scott GrissomCh 7 Designing Classes Slide 11 Class methods (7.15) static methods are associated with a class and not an instance Math.sqrt() public static void main(String [] args){ Game g = new Game(); g.play(); }