CS260: Object Oriented Programming Review - February 9, 2016 - - PowerPoint PPT Presentation
CS260: Object Oriented Programming Review - February 9, 2016 - - PowerPoint PPT Presentation
CS260: Object Oriented Programming Review - February 9, 2016 Test next time Objects & Classes Overview Inheritance UML Basic Programming Stuff... Objects And Classes What is an Object? What are
Overview
- Test next time…
○ Objects & Classes ○ Inheritance ○ UML ○ Basic Programming Stuff...
Objects And Classes
- What is an Object?
- What are the two parts of an Object?
- What is a Class?
- What is a field?
- What is a Method?
- What is a Constructor?
Class Definition
- Classes
a. What does a class definition look like?
public class ClassNameHere { //this is where fields go ClassNameHere(){ //this is where we set up the class } //this is where methods go }
Class Definition
- Classes - Given a Class Definition
a. What fields are in this Class? b. What methods are in this Class? c. Label the section representing the Class State d. Label the section representing the Class Behaviors e. What parameters does the Constructor take?
OOP - Inheritance
- What is inheritance?
- What does inheritance look like in UML?
- What does inheritance look like in code?
○ Standard Class declaration but with “extends” keyword
public class ChildClass extends ParentClass { //this is where fields go ChildClass(){ //this is where we set up the class } //this is where methods go }
Translate into UML
public class Bubble { int x, y; int radius; int col; Bubble(int startX, int startY, int rad, int c){ x = startX; y = startY; radius = rad; col = c; } public void floatUp(){ if(y < 0){ y = height; } y--; } public void drawBubble(){ noFill(); stroke(col); ellipse(x, y, radius, radius); } }
Translate into UML
- From Text Description
○ Cartoon Characters ■ There is a Bird Class ■ The Bird Class has a Beak Class ■ Tweety Bird inherits from the Bird Class ■ A Duck Class inherits from the Bird Class ■ Daffy Duck and Donald Duck, and Scrooge McDuck Classes all inherit from the Duck Class
UML Class Diagrams
- Label
○ Class Name ○ State ○ Behavior ○ Fields ○ Methods
- Relationships
○ X Inherits from Y (is a) ○ A Belongs to B (B has a A)
Basic Programming Stuff...
- PascalCase vs camelCase
- Constants
- Data types
- Loops
- Indentation
- Switch-Case
- Arrays
- Functions
- Scope