13. #include <iostream>
using namespace std;
class Dog { // Dog
public:
string name; // ( )
void bark(); // ( )
}; //Dog ( ";" )
int main (int argc, char * const argv[]) { //
}
14. software systems.
Interface and Implementation
To invent programs, you need to be able to capture abstractions and express them in t
design. It’s the job of a programming language to help you do this. The language shoul
process of invention and design by letting you encode abstractions that reveal the way
It should let you make your ideas concrete in the code you write. Surface details shou
the architecture of your program.
All programming languages provide devices that help express abstractions. In essence
are ways of grouping implementation details, hiding them, and giving them, at least t
a common interface—much as a mechanical object separates its interface from its impl
illustrated in “Interface and Implementation” .
Figure 2-1 Inte rfa ce a nd Im ple m e nta tion
interface implementation
11
10
9
8
7
6
Looking at such a unit from the inside, as the implementor, you’d be concerned with w
composed of and how it works. Looking at it from the outside, as the user, you’re conc
with what it is and what it does. You can look past the details and think solely in term
26. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
};
#endif
27. #include "testApp.h"
void testApp::setup(){
}
void testApp::update(){
}
void testApp::draw(){
}
void testApp::keyPressed(int key){
}
void testApp::keyReleased(int key){
}
void testApp::mouseMoved(int x, int y){
}
void testApp::mouseDragged(int x, int y, int button){
}
void testApp::mousePressed(int x, int y, int button){
}
void testApp::mouseReleased(int x, int y, int button){
}
void testApp::windowResized(int w, int h){
}
28.
29.
30.
31.
32.
33.
34.
35.
36. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofBlob.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
ofBlob blob; //ofBlob
};
#endif
43. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofBlob.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
ofBlob blob; //ofBlob
};
#endif
50. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofBlob.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
ofBlob blob; //ofBlob
};
65. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofBlob.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
vector <ofBlob> blobs; //ofBlob Vector
};
66. #include "testApp.h"
void testApp::setup(){
ofBackground(0, 0, 0);
ofSetCircleResolution(64);
ofEnableAlphaBlending();
ofSetFrameRate(30);
}
void testApp::update(){
for (int i = 0; i < blobs.size(); i++) {
blobs[i].update();
}
}
void testApp::draw(){
for (int i = 0; i < blobs.size(); i++) {
blobs[i].draw();
}
}
...( )...
67. void testApp::mouseReleased(int x, int y, int button){
ofBlob b = ofBlob(); // ofBlob
b.setPos(ofPoint(mouseX, mouseY)); //
b.setDim(ofRandom(10,40)); //
b.setSpeed(ofPoint(ofRandom(-5, 5), ofRandom(-5, 5))); //
blobs.push_back(b);
}
...( )
75. #ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofBlob.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
vector <ofBlob> blobs; //ofBlob Vector
};
76. #include "testApp.h"
void testApp::setup(){
ofBackground(0, 0, 0);
ofSetCircleResolution(64);
ofEnableAlphaBlending();
ofSetFrameRate(30);
ofBlob b = ofBlob();
b.setPos(ofPoint(ofGetWidth()/2, ofGetHeight()/2));
b.setDim(ofGetHeight()/3);
blobs.push_back(b);
}
void testApp::update(){
for (int i = 0; i < blobs.size(); i++) {
blobs[i].update();
}
}
void testApp::draw(){
for (int i = 0; i < blobs.size(); i++) {
blobs[i].draw();
}
77. void testApp::keyPressed(int key){
switch (key) {
case 'f':
ofSetFullscreen(true);
break;
}
}
void testApp::keyReleased(int key){
}
void testApp::mouseMoved(int x, int y){
}
void testApp::mouseDragged(int x, int y, int button){
}
void testApp::mousePressed(int x, int y, int button){
int bSize = blobs.size();
for (int i = 0; i < bSize; i++) {
ofPoint p = blobs[i].getPos();
float dist = ofDist(p.x, p.y, mouseX, mouseY);
float dim = blobs[i].getDim();
ofPoint pos = blobs[i].getPos();