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

Info icon This preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2 Module 32 Category: OO Concepts Topic: Design Objectives Some basic design concepts
Image of page 1

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

View Full Document Right Arrow Icon
CS 2 Introduction to Object Oriented Programming Module 32 OO Concepts Design
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
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!
Image of page 4
class BigDaddy { public BigDaddy() { System.out.println("Who’s 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!!!"); } }
Image of page 5

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

View Full Document Right Arrow Icon
class Bad extends BadDad { private int x = 0; // bad programming! public Bad() { // Constructor System.out.println("Who’s 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()); } }
Image of page 6
What's the output? Who’s your Daddy? This is BadDad! About to set x to 42 Verifying… x = 42 Who’s Bad? Value of x is now: 0
Image of page 7

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

View Full Document Right Arrow Icon
Questions?
Image of page 8
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.
Image of page 9

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

View Full Document Right Arrow Icon
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
Image of page 10
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? Who has to know about what?
Image of page 11

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

View Full Document Right Arrow Icon
Simple Steps 5. Put the design on paper (or the wall) Indicate classes Their methods Their fields Who they need to talk to Indicate hierarchies 6. Run the cases or scenarios against the design Modify, modify, modify 7. Code a class at a time USE A TEST/DEBUG main IN EACH Start at the bottom Compile & test frequently
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern