CS2_32_OODesign - CS2 Module 32 Category: OO Concepts...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS2 Module 32 Category: OO Concepts Topic: Design Objectives Some basic design concepts CS 2 Introduction to Object Oriented Programming Module 32 OO Concepts Design Some Guidelines Make all fields private and consistently use accessors and modifiers. Any variable that "can" be a method variable "should" be a method variable. Common error : Making instance variables or class variables of items that should be (temporary) method variables. All classes should have: toString test main which tests all methods (if possible). DEBUG constant Some Guidelines Initialize appropriate instance variables in the constructor. Initialize static (class) variables when declared. Applications that require a method call to startup should do so from a main method and not a constructor. Rule of thumb: Constructors should be "fast", initialize things and exit. See following example! class BigDaddy { public BigDaddy() { System.out.println("Whos your Daddy?"); } } class BadDad extends BigDaddy { public BadDad() { // Constructor System.out.println("This is BadDad!"); ruin(); // which ruin method??? } public void ruin() { // ruin // Notice this does NOT get called! System.out.println("Maniacal Laugh!!!"); } } class Bad extends BadDad { private int x = 0; // bad programming! public Bad() { // Constructor System.out.println("Whos Bad?"); } public void setX(int x) { // x Modifier this.x = x; } public int getX() { // x Accessor return x; } public void ruin() { // ruin System.out.println("About to set x to 42"); setX(42); System.out.println("Verifying... x = " + getX()); } public static void main(String args) { // main Bad b = new Bad(); System.out.println("Value of x is now: " + b.getX()); } } What's the output? Whos your Daddy? This is BadDad! About to set x to 42 Verifying x = 42 Whos Bad? Value of x is now: 0 Questions? Basic Design Software design is an art not a science It is best learned by experience hopefully with some expert guidance This lecture will not make you an expert The goal is to give you a simple basic structure to get you started in the process. No matter what your major you will take a number of design courses before you leave Tech. Simple Steps 1. Understand the problem Problem statement Discussion with clients 2. Develop cases or scenarios Functions that your program must perform Might be menu items Might be events which trigger action 3. Plain English Describe situation Describe scenarios Simple Steps 4. Apply Object Oriented thinking Analyze the plain English Nouns - Objects Verbs - Methods Imagine the structure "has a" relationships (fields) "is a" hierarchical structures Consider communication Who has to communicate with whom?...
View Full Document

This note was uploaded on 01/23/2012 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

Page1 / 74

CS2_32_OODesign - CS2 Module 32 Category: OO Concepts...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online