
1
CS 112 Introduction to
Programming
Lecture #16:
Defining Classes
http://flint.cs.yale.edu/cs112/
2
Outline
rAdmin. and review
rClasses and objects
rDefining classes
mBasic syntax
mExamples
3
PrintMonth GetMonthDays
GetMonthDays();
PrintMonth();
Main
Summary: Method Control Flow
4
Summary
rDesign
•Top-down; stepwise refinement
rImplementation and testing
•Write the simple functions first
•Write a piece and test a piece
–Test a method
»using some dummy method calls, e.g.
Call the method in Main() with some typical test cases
»using Visual Studio Immediate window
5
Outline
rAdmin. and review
ØClasses and objects
rDefining a class
mBasic syntax
mExamples
6
Object-Oriented Design
rThe focus of methods is on doing things;
roughly speaking, we can say that methods
focus on the verbs.
rIn object-oriented design, we focus on the
nouns
mIn object-oriented design, we tend to group
methods together according to the nouns
mImportant for large, complex programs