1 What makes a Good Class Original by Dr. Stumpf – modified by Dr V Copyright 1996-98 © Dale Carnegie & Associates, Inc.

Slides:



Advertisements
Similar presentations
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Written by: Dr. JJ Shepherd
CMSC 202 Inheritance. Aug 6, Object Relationships An object can have another object as one of instance variables. The Person class had two Date.
CS 106 Introduction to Computer Science I 11 / 09 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
CS/ENGRD 2110 FALL 2014 Lecture 3: Fields, getters and setters, constructors, testing 1.
Address Book in JAVA By What is Address Book Address Book is book or database used for storing entries called contacts Each contact.
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Writing Classes (Chapter 4)
CS/ENGRD 2110 SPRING 2015 Lecture 3: Fields, getters and setters, constructors, testing 1.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA Prof. Dr. Paulo Brasko Ferreira Fall 2014.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 3 Part 1.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
For Wednesday No new reading Complete WebCT quiz.
CSC 142 Computer Science II Zhen Jiang West Chester University
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 02 – Classes, Objects, Instances Richard Salomon and Umesh Patel Centre.
Documentation and Programming Style Appendix A © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
Data Types and Operations On Data Objective To understand what data types are The need to study data types To differentiate between primitive types and.
© 2004 Pearson Addison-Wesley. All rights reserved September 12, 2007 Encapsulation ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
CMSC 202 Inheritance I Class Reuse with Inheritance.
Classes Modeling the Object. Objects model the world Classes are programmer defined types that model the parts of a system Class serve as blueprints for.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Classes and Objects CS177 Rec 10. Announcements Project 4 is posted ◦ Milestone due on Nov. 12. ◦ Final submission due on Nov. 19. Exam 2 on Nov. 4 ◦
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Centre for Computer Technology ICT115 Object Oriented Design and Programming Week 03 – Class Design, Object Discovery and Use Richard Salomon Centre for.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Dale Roberts Object Oriented Programming using Java - Getters and Setters Dale Roberts, Lecturer Computer Science, IUPUI
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
Outline Anatomy of a Class Encapsulation Anatomy of a Method Copyright © 2014 Pearson Education, Inc.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
יסודות מדעי המחשב – תרגול 6
Andrew(amwallis) Classes!
The need for Programming Languages
Inheritance ITI1121 Nour El Kadri.
Objects, Classes, and Methods (PART 1)
Creating Your OwnClasses
HKCT Java OOP Unit 02 Object Oriented Programming in Java Unit 02 Methods, Classes, and Objects 1.
בניית מחלקות.
Defining Your Own Classes Part 1
Chapter 4: Writing classes
Inheritance I Class Reuse with Inheritance
An Introduction to Java – Part II
CSC 113: Computer programming II
CMSC 202 Inheritance.
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
בניית מחלקות.
ITunes Lab Copyright © 2012 Pearson Education, Inc.
Class Reuse with Inheritance
Adapted from slides by Marty Stepp and Stuart Reges
תירגול 9 אובייקטים.
CS 302 Week 9 Jim Williams.
Today’s topics UML Diagramming review of terms
مظفر بگ محمدی دانشگاه ایلام
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Midterm Exam Information
Introduction to Objects & Classes
Instance Method – CSC142 Computer Science II
Announcements Lab 5 was due today Program 3 due Monday by 12pm
Presentation transcript:

1 What makes a Good Class Original by Dr. Stumpf – modified by Dr V Copyright © Dale Carnegie & Associates, Inc.

2 What makes a Good Class By using a clean looking design a class can be understood quickly. There are several issues: Sequencing –Indentation and Formatting

3 What to Include in a Class Two constructors: –Default constructor public Employee(){}; –Populating Constructor public Employee(double rate, double hours) { this.rate = rate; this.hours = hours; }

4 What to Include in a Class toString part one: public String toString() { String classDescription = "Employee" + "["; classDescription += "name" + " = "; classDescription += name; classDescription += ", "; classDescription += "hours" + " = ";

5 What to Include in a Class toString part two: classDescription += hours; classDescription += ", "; classDescription += “rate" + " = "; classDescription += rate; classDescription += "]"; return classDescription; }

6 What to Include in a Class Mutators (modifiers): called setters public setHours(double hours) {this.hours = hours;} public setRate(double rate) {this.rate = rate;}

7 What to Include in a Class Accessors: called getters public double getHours() {return hours;} public double getRate() {return rate;}

8 Sequencing Class Elements There is variety in styles here. A few authors place attributes last. Most, however, prefer to place attributes first. Then constructors. Lastly methods sequenced alphabetically.

9 Indentation and Formatting The big argument is the placement of braces James Gosling of Sun who is considered the primary author of Java uses the following style: public double computeWage(double hours){ if (hours < 40){ return hours * rate; } else{ return (hours - 40) * rate * * rate; } }

10 Indentation and Formatting Others prefer to line up the braces as follows: public double computeWage(double hours) { if (hours < 40) { return hours * rate; } else { return (hours - 40) * rate * * rate; } }

11 Indentation and Formatting The instructors in the CIS all prefer the second way. This goes against the majority of Computer Scientists. However, the second way is much easier to inspect for problems

12 Close By using clean a looking design a class can be understood quickly. There are several issues: –What to include –Sequencing –Indentation and Formatting