├── Books ├── Design patterns in Java.pdf ├── DesignPatterns.pdf └── head first design patterns - ora 2004.pdf ├── CODE ├── WDP │ └── initial │ │ ├── Character.pde │ │ ├── Enemy.pde │ │ ├── HeavyMovement.pde │ │ ├── MovementStrategy.pde │ │ └── initial.pde └── WODP │ └── initial │ ├── BouncingEnemy.pde │ ├── Character.pde │ ├── Enemy.pde │ ├── HeavyEnemies.pde │ ├── RandomEnemy.pde │ ├── RightEnemies.pde │ ├── RightHeavyEnemies.pde │ └── initial.pde ├── CS ___ DESIGN PATTERNS AND CODE SMELLS(1).pdf ├── Papers ├── Composite Design Patterns.pdf ├── design patterns between programming and engineering.pdf ├── generic models.pdf └── listen for design.pdf └── README.md /Books/Design patterns in Java.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtaYurtsever/CS489-Design-Patterns/45aaf1b570a1a54c5712b2411ac5f4f741de9254/Books/Design patterns in Java.pdf -------------------------------------------------------------------------------- /Books/DesignPatterns.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtaYurtsever/CS489-Design-Patterns/45aaf1b570a1a54c5712b2411ac5f4f741de9254/Books/DesignPatterns.pdf -------------------------------------------------------------------------------- /Books/head first design patterns - ora 2004.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtaYurtsever/CS489-Design-Patterns/45aaf1b570a1a54c5712b2411ac5f4f741de9254/Books/head first design patterns - ora 2004.pdf -------------------------------------------------------------------------------- /CODE/WDP/initial/Character.pde: -------------------------------------------------------------------------------- 1 | //initial class 2 | class Character{ 3 | private float x,y; 4 | private float xSpeed,ySpeed; 5 | private float speed; 6 | private float size; 7 | public Character(float x, float y){ 8 | this.x = x; 9 | this.y = y; 10 | speed = 6; 11 | size = 50; 12 | this.xSpeed = 0; 13 | this.ySpeed = 0; 14 | } 15 | 16 | public void render(){ 17 | fill(200,50,50); 18 | noStroke(); 19 | rect(x,y,size,size); 20 | } 21 | 22 | private void checkCollisionWithSides(){ 23 | if(x<=-xSpeed){ 24 | x = 0; 25 | xSpeed = 0; 26 | } 27 | if(x+xSpeed >= width-size){ 28 | x = width - size; 29 | xSpeed = 0; 30 | } 31 | if(y<=-ySpeed){ 32 | y = 0; 33 | ySpeed = 0; 34 | } 35 | if(y+ySpeed >= width-size){ 36 | y = width - size; 37 | ySpeed = 0; 38 | } 39 | 40 | } 41 | 42 | public void update(){ 43 | checkCollisionWithSides(); 44 | if(xSpeed != 0 || ySpeed != 0){ 45 | float sp = sqrt(xSpeed*xSpeed+ySpeed*ySpeed); 46 | xSpeed = speed * xSpeed/sp; 47 | ySpeed = speed * ySpeed/sp; 48 | } 49 | 50 | this.x += this.xSpeed; 51 | this.y += this.ySpeed; 52 | //this.xSpeed = 0; 53 | //this.ySpeed = 0; 54 | } 55 | 56 | public void moveUp(){ 57 | this.ySpeed += -speed; 58 | } 59 | 60 | public void moveDown(){ 61 | this.ySpeed += speed; 62 | } 63 | 64 | public void moveLeft(){ 65 | this.xSpeed += -speed; 66 | } 67 | 68 | public void moveRight(){ 69 | this.xSpeed += speed; 70 | } 71 | 72 | public boolean isHit(ArrayList enemies){ 73 | for(Enemy e:enemies){ 74 | if( (e.getX() >= x && e.getX() <= x+size || 75 | e.getX()+e.getSize() >= x && e.getX()+e.getSize() = y && e.getY() <= y+size || 77 | e.getY()+e.getSize() >= y && e.getY()+e.getSize() <= y+size)){ 78 | println("hit"); 79 | return true; 80 | } 81 | } 82 | return false; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /CODE/WDP/initial/Enemy.pde: -------------------------------------------------------------------------------- 1 | //initial class 2 | class Enemy{ 3 | public float x,y; 4 | public float size; 5 | protected float xSpeed,ySpeed; 6 | private MovementStrategy strategy; 7 | 8 | public Enemy(float x, float y, MovementStrategy strategy) { 9 | this.x = x; 10 | this.y = y; 11 | this.size = 50; 12 | this.xSpeed = random(20)-10; 13 | this.ySpeed = random(20)-10; 14 | 15 | this.strategy = strategy; 16 | } 17 | 18 | public void render(){ 19 | fill(0,0,255); 20 | rect(x,y,size,size); 21 | }; 22 | 23 | public void update(){ 24 | strategy.move(this); 25 | }; 26 | 27 | public float getX(){return x;} 28 | public float getY(){return y;} 29 | public float getSize(){return size;} 30 | 31 | } 32 | -------------------------------------------------------------------------------- /CODE/WDP/initial/HeavyMovement.pde: -------------------------------------------------------------------------------- 1 | class HeavyMovementDecorator implements MovementStrategy{ 2 | MovementStrategy strategy; 3 | public HeavyMovementDecorator(MovementStrategy strategy){ 4 | this.strategy = strategy; 5 | } 6 | 7 | void move(Enemy e){ 8 | e.ySpeed += 0.2; 9 | strategy.move(e); 10 | } 11 | } 12 | 13 | class RightMovementDecorator implements MovementStrategy{ 14 | MovementStrategy strategy; 15 | public RightMovementDecorator(MovementStrategy strategy){ 16 | this.strategy = strategy; 17 | } 18 | 19 | void move(Enemy e){ 20 | e.xSpeed += 0.3; 21 | strategy.move(e); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CODE/WDP/initial/MovementStrategy.pde: -------------------------------------------------------------------------------- 1 | interface MovementStrategy{ 2 | public void move(Enemy e); 3 | } 4 | 5 | class RandomMovementStrategy implements MovementStrategy{ 6 | public void move(Enemy e){ 7 | if(e.x < 0){ 8 | e.xSpeed = random(10); 9 | e.ySpeed = random(20)-10; 10 | } 11 | if(e.x+e.size > width){ 12 | e.xSpeed = -random(10); 13 | e.ySpeed = random(20)-10; 14 | } 15 | if(e.y < 0){ 16 | e.ySpeed = random(10); 17 | e.xSpeed = random(20)-10; 18 | } 19 | if(e.y+e.size > height){ 20 | e.ySpeed = -random(10); 21 | e.xSpeed = random(20)-10; 22 | } 23 | 24 | e.x += e.xSpeed; 25 | e.y += e.ySpeed; 26 | 27 | } 28 | } 29 | 30 | class BouncingMovementStrategy implements MovementStrategy{ 31 | public void move(Enemy e){ 32 | if(e.x < 0 || 33 | e.x+e.size > width) 34 | e.xSpeed = -e.xSpeed; 35 | if(e.y < 0 || 36 | e.y+e.size > height) 37 | e.ySpeed = -e.ySpeed; 38 | 39 | e.x += e.xSpeed; 40 | e.y += e.ySpeed; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CODE/WDP/initial/initial.pde: -------------------------------------------------------------------------------- 1 | Character c; 2 | ArrayList enemies; 3 | void setup(){ 4 | size(800,800); 5 | frameRate(60); 6 | c = new Character(200,200); 7 | enemies = new ArrayList(); 8 | enemies.add( 9 | new Enemy(400,400,new RightMovementDecorator( 10 | new HeavyMovementDecorator( 11 | new BouncingMovementStrategy() 12 | ) 13 | )) 14 | ); 15 | } 16 | 17 | void draw(){ 18 | background(0); 19 | c.update(); 20 | for(Enemy e:enemies){ 21 | e.update(); 22 | } 23 | c.render(); 24 | for(Enemy e:enemies) 25 | e.render(); 26 | if(c.isHit(enemies)) 27 | stop(); 28 | 29 | } 30 | 31 | void keyPressed(){ 32 | //System.out.println(key); 33 | if(key == 'a') 34 | c.moveLeft(); 35 | if(key == 'd') 36 | c.moveRight(); 37 | if(key == 'w') 38 | c.moveUp(); 39 | if(key == 's') 40 | c.moveDown(); 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /CODE/WODP/initial/BouncingEnemy.pde: -------------------------------------------------------------------------------- 1 | class BouncingEnemy implements Enemy{ 2 | public float x,y; 3 | public float size; 4 | protected float xSpeed,ySpeed; 5 | 6 | 7 | public BouncingEnemy(float x, float y){ 8 | this.x =x; 9 | this.y = y; 10 | size = 50; 11 | xSpeed = random(20)-10; 12 | ySpeed = random(20)-10; 13 | } 14 | 15 | public void render(){ 16 | fill(0,0,255); 17 | rect(x,y,size,size); 18 | } 19 | 20 | public void update(){ 21 | if(x < 0 || x + size > width) 22 | xSpeed = -xSpeed; 23 | if(y < 0 || y + size > height) 24 | ySpeed = -ySpeed; 25 | 26 | x += xSpeed; 27 | y += ySpeed; 28 | } 29 | 30 | public float getX(){return x;} 31 | public float getY(){return y;} 32 | public float getSize(){return size;} 33 | 34 | } 35 | -------------------------------------------------------------------------------- /CODE/WODP/initial/Character.pde: -------------------------------------------------------------------------------- 1 | //initial class 2 | class Character{ 3 | private float x,y; 4 | private float xSpeed,ySpeed; 5 | private float speed; 6 | private float size; 7 | public Character(float x, float y){ 8 | this.x = x; 9 | this.y = y; 10 | speed = 6; 11 | size = 50; 12 | this.xSpeed = 0; 13 | this.ySpeed = 0; 14 | } 15 | 16 | public void render(){ 17 | fill(200,50,50); 18 | noStroke(); 19 | rect(x,y,size,size); 20 | } 21 | 22 | private void checkCollisionWithSides(){ 23 | if(x<=-xSpeed){ 24 | x = 0; 25 | xSpeed = 0; 26 | } 27 | if(x+xSpeed >= width-size){ 28 | x = width - size; 29 | xSpeed = 0; 30 | } 31 | if(y<=-ySpeed){ 32 | y = 0; 33 | ySpeed = 0; 34 | } 35 | if(y+ySpeed >= width-size){ 36 | y = width - size; 37 | ySpeed = 0; 38 | } 39 | 40 | } 41 | 42 | public void update(){ 43 | checkCollisionWithSides(); 44 | if(xSpeed != 0 || ySpeed != 0){ 45 | float sp = sqrt(xSpeed*xSpeed+ySpeed*ySpeed); 46 | xSpeed = speed * xSpeed/sp; 47 | ySpeed = speed * ySpeed/sp; 48 | } 49 | 50 | this.x += this.xSpeed; 51 | this.y += this.ySpeed; 52 | //this.xSpeed = 0; 53 | //this.ySpeed = 0; 54 | } 55 | 56 | public void moveUp(){ 57 | this.ySpeed += -speed; 58 | } 59 | 60 | public void moveDown(){ 61 | this.ySpeed += speed; 62 | } 63 | 64 | public void moveLeft(){ 65 | this.xSpeed += -speed; 66 | } 67 | 68 | public void moveRight(){ 69 | this.xSpeed += speed; 70 | } 71 | 72 | public boolean isHit(ArrayList enemies){ 73 | for(Enemy e:enemies){ 74 | if( (e.getX() >= x && e.getX() <= x+size || 75 | e.getX()+e.getSize() >= x && e.getX()+e.getSize() = y && e.getY() <= y+size || 77 | e.getY()+e.getSize() >= y && e.getY()+e.getSize() <= y+size)){ 78 | println("hit"); 79 | return true; 80 | } 81 | } 82 | return false; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /CODE/WODP/initial/Enemy.pde: -------------------------------------------------------------------------------- 1 | //initial class 2 | interface Enemy{ 3 | void render(); 4 | void update(); 5 | } 6 | -------------------------------------------------------------------------------- /CODE/WODP/initial/HeavyEnemies.pde: -------------------------------------------------------------------------------- 1 | class HeavyBouncingEnemy extends BouncingEnemy{ 2 | public HeavyBouncingEnemy(float x, float y){ 3 | super(x,y); 4 | } 5 | 6 | void update(){ 7 | this.ySpeed += 0.2; 8 | super.update(); 9 | } 10 | } 11 | 12 | class HeavyRandomEnemy extends RandomEnemy{ 13 | public HeavyRandomEnemy(float x, float y){ 14 | super(x,y); 15 | } 16 | 17 | void update(){ 18 | this.ySpeed += 0.2; 19 | super.update(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CODE/WODP/initial/RandomEnemy.pde: -------------------------------------------------------------------------------- 1 | class RandomEnemy implements Enemy{ 2 | public float x,y; 3 | public float size; 4 | protected float xSpeed,ySpeed; 5 | 6 | 7 | public RandomEnemy(float x, float y){ 8 | this.x =x; 9 | this.y = y; 10 | size = 50; 11 | xSpeed = random(20)-10; 12 | ySpeed = random(20)-10; 13 | } 14 | 15 | public void render(){ 16 | fill(0,0,255); 17 | rect(x,y,size,size); 18 | } 19 | 20 | public void update(){ 21 | if(x < 0){ 22 | xSpeed = random(10); 23 | ySpeed = random(20)-10; 24 | } 25 | if(x+size > width){ 26 | xSpeed = -random(10); 27 | ySpeed = random(20)-10; 28 | } 29 | if(y < 0){ 30 | ySpeed = random(10); 31 | xSpeed = random(20)-10; 32 | } 33 | if(y+size > height){ 34 | ySpeed = -random(10); 35 | xSpeed = random(20)-10; 36 | } 37 | 38 | x += xSpeed; 39 | y += ySpeed; 40 | } 41 | 42 | public float getX(){return x;} 43 | public float getY(){return y;} 44 | public float getSize(){return size;} 45 | 46 | } 47 | -------------------------------------------------------------------------------- /CODE/WODP/initial/RightEnemies.pde: -------------------------------------------------------------------------------- 1 | class RightBouncingEnemy extends BouncingEnemy{ 2 | public RightBouncingEnemy(float x, float y){ 3 | super(x,y); 4 | } 5 | 6 | void update(){ 7 | this.xSpeed += 0.3; 8 | super.update(); 9 | } 10 | } 11 | 12 | class RightRandomEnemy extends RandomEnemy{ 13 | public RightRandomEnemy(float x, float y){ 14 | super(x,y); 15 | } 16 | 17 | void update(){ 18 | this.xSpeed += 0.3; 19 | super.update(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CODE/WODP/initial/RightHeavyEnemies.pde: -------------------------------------------------------------------------------- 1 | class RightHeavyBouncingEnemy extends HeavyBouncingEnemy{ 2 | public RightHeavyBouncingEnemy(float x, float y){ 3 | super(x,y); 4 | } 5 | 6 | void update(){ 7 | this.ySpeed += 0.3; 8 | super.update(); 9 | } 10 | } 11 | 12 | class RightHeavyRandomEnemy extends HeavyRandomEnemy{ 13 | public RightHeavyRandomEnemy(float x, float y){ 14 | super(x,y); 15 | } 16 | 17 | void update(){ 18 | this.ySpeed += 0.3; 19 | super.update(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CODE/WODP/initial/initial.pde: -------------------------------------------------------------------------------- 1 | Character c; 2 | ArrayList enemies; 3 | void setup(){ 4 | size(800,800); 5 | frameRate(60); 6 | c = new Character(200,200); 7 | enemies = new ArrayList(); 8 | } 9 | 10 | void draw(){ 11 | background(0); 12 | c.update(); 13 | for(Enemy e:enemies){ 14 | e.update(); 15 | } 16 | c.render(); 17 | for(Enemy e:enemies) 18 | e.render(); 19 | if(c.isHit(enemies)) 20 | stop(); 21 | 22 | } 23 | 24 | void keyPressed(){ 25 | //System.out.println(key); 26 | if(key == 'a') 27 | c.moveLeft(); 28 | if(key == 'd') 29 | c.moveRight(); 30 | if(key == 'w') 31 | c.moveUp(); 32 | if(key == 's') 33 | c.moveDown(); 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /CS ___ DESIGN PATTERNS AND CODE SMELLS(1).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtaYurtsever/CS489-Design-Patterns/45aaf1b570a1a54c5712b2411ac5f4f741de9254/CS ___ DESIGN PATTERNS AND CODE SMELLS(1).pdf -------------------------------------------------------------------------------- /Papers/Composite Design Patterns.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtaYurtsever/CS489-Design-Patterns/45aaf1b570a1a54c5712b2411ac5f4f741de9254/Papers/Composite Design Patterns.pdf -------------------------------------------------------------------------------- /Papers/design patterns between programming and engineering.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtaYurtsever/CS489-Design-Patterns/45aaf1b570a1a54c5712b2411ac5f4f741de9254/Papers/design patterns between programming and engineering.pdf -------------------------------------------------------------------------------- /Papers/generic models.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtaYurtsever/CS489-Design-Patterns/45aaf1b570a1a54c5712b2411ac5f4f741de9254/Papers/generic models.pdf -------------------------------------------------------------------------------- /Papers/listen for design.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtaYurtsever/CS489-Design-Patterns/45aaf1b570a1a54c5712b2411ac5f4f741de9254/Papers/listen for design.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CS489 Design Patterns Tutorial Resources 2 | You can access the example code in the code folder 3 | 4 | ## How to Study 5 | ### Books 6 | - Design Patterns in Java 7 | - I believe this book has the best structure. It shows codes and examples all written java. Simple to understand talks about all important aspects. Definitely the go to handbook of mine. 8 | - Desing Patterns: Elements of Reusable Object-Oriented Software Development 9 | - First book that defines the design patterns. Some patterns are explained with less detail. But overall this must one of the first resources you need to look out for when learning about design patterns 10 | - Head First Design Patterns 11 | - This is our coursebook thus it is the best place to study for exams. The way it teaches is not suitable for me, other two books give more concrete examples. 12 | 13 | ### Papers 14 | Unlike most other things in computer science design patterns are first defined in the book not in a paper, so there is no initial paper for design patterns. Below are some of my favourite papers on the subject. 15 | - Learning to Listen for Design 16 | - This is the paper that the first part of our lecture is based on. It touches some very interesting points. Especially Voice and Hearing chapters are really fun to read. 17 | - Design Patterns Generic Models 18 | - Simplest paper of all. It goes over all of the design patterns in a simple fashion. Splits these patterns into groups in a different way than the other resources. 19 | - Composite Design Patterns 20 | - Very quick read that explains how to create composite patterns that consist of more than one design pattern. 21 | - Design Patterns Between Programming and Engineering 22 | - This pattern very wonderfully gives an overview for the use of design patterns. Again a very quick read. 23 | 24 | ### Videos and Podcasts 25 | - [GOTO 2014 • Root Cause Analysis of some Faults in Design Patterns • Ralph E. Johnson](https://www.youtube.com/watch?v=ImUcJctyUQ0) 26 | - Ralph Johnson is one of the writers of the Design Patterns: Elements of Reusable Object-Oriented Software Development. In this talk he is talking about modern advances in programming that some of their defined design patterns cannot keep up. It is beautiful retrospective talk. 27 | - [Erich Gamma Podcast](https://www.youtube.com/watch?v=V8-KPJS2Bjw) 28 | - Erich Gamma is another one of the writers of the Design Patterns: Elements of Reusable Object-Oriented Software Developent In this podcast he generally talks about his career but at the start they talk about his greatest work design patterns. All of the podcast is really fun to listen. 29 | 30 | ### Codes 31 | Codes we have written in the class can be found inside the codes folder. WODP folder includes the implementation without the design patterns, WDP includes the implementation with the design patterns. 32 | To run the codes you need the processing ide which can be get from [here](https://processing.org/download). You can learn more about the processing from [here](https://processing.org/tutorials/) 33 | --------------------------------------------------------------------------------