# Thinking Object Oriented

**URL:** <https://discourse.processing.org/t/thinking-object-oriented/17448>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [January 30, 2020, 1:41pm UTC](https://discourse.processing.org/t/thinking-object-oriented/17448 "2020-01-30T13:41:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeidaraLP](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@DeidaraLP](https://discourse.processing.org/u/DeidaraLP)\
**Post date:** [January 30, 2020, 1:41pm UTC](https://discourse.processing.org/t/thinking-object-oriented/17448/1 "2020-01-30T13:41:29Z")

</div>

Hey folks.

So for a school assignment, we had to create some kind of game with at least two self-defined classes while using object-oriented programming. However, I’m finding it quite hard to implement this OOP way of thinking. The game I created is just a complete copy of the Flappy Birds game.

The problem is, that i didn’t really find use for classes since i could just write all the code on the main page. I just got some feedback for the teacher and she said my code was very disorganized and that i needed an extra class to fulfill requirements.

Can anybody give me some tips or help me with how to organize my code and maybe come up with some ideas on what my two classes could be?

> **[ValdemarBirkegaardPetersen/Birds](https://github.com/ValdemarBirkegaardPetersen/Birds/tree/master)**
>
> Contribute to ValdemarBirkegaardPetersen/Birds development by creating an account on GitHub.

I uploadet the code at github above.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 30, 2020, 2:30pm UTC](https://discourse.processing.org/t/thinking-object-oriented/17448/2 "2020-01-30T14:30:56Z")

</div>

> [@DeidaraLP](#):
>
> … and she said my code was very disorganized and that I needed an extra class to fulfill requirements.

- OOP is basically an approach of how to organize code as objects.
- Each object requires variables to describe its characteristics & current state.
- Those variables become fields (a.K.a. properties) of the class which describes that object.
- Then we write functions which deal w/ those field variables.
- Those functions become methods of that object’s class.
- Here’s a simple game that got classes for the player (Beaver), the grass animation (Grass), the player’s objective (Stick) and 1 more to save how many sticks the player caught (Score):  
[sketchpad](http://Studio.ProcessingTogether.com/sp/pad/export/ro.9bTfM49wCIJza)
- And a beginner tutorial about OOP & classes:  
[Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials \> Learning the Java Language)](http://Docs.Oracle.com/javase/tutorial/java/concepts/index.html)

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [January 30, 2020, 3:44pm UTC](https://discourse.processing.org/t/thinking-object-oriented/17448/3 "2020-01-30T15:44:19Z")

</div>

I love the title to this discussion, “Thinking Object Oriented” because it says it all.

OO requires you to identify the entities (classes) that make up your application _ **before** _ you start writing source code. To retrofit classes into a procedural program is very messy and will probably involve you re-writing most of the original code.

I assume you have been taught the basics of classes and objects so I am not going to rehash it here but in the case of a Flappy Birds type program there are two obvious entities that could be represented as classes

1. FlappyBird
2. Obstacle (the entity to be avoided by the bird)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 30, 2020, 4:40pm UTC](https://discourse.processing.org/t/thinking-object-oriented/17448/4 "2020-01-30T16:40:05Z")

</div>

Object Oriented Programming is a way to organize your code into chunks / sections (classes).

Without it, variables (x,y…) and functions (drawBird())…) are all over the place.

With the classes you can sort it into classes. The class is cookie maker, the objects are the cookies:

- So the class contains the properties of the cookies (color, position) and its functions (beWarm(), beEaten()).
- The objects are the individual cookies, with different color, position and speed.

Make a class Bird and a class Obstacle. Not a class GameSetup.

**Links**

See also [https://github.com/Kango/Processing-snippets/wiki/Object-Oriented-Programming](https://github.com/Kango/Processing-snippets/wiki/Object-Oriented-Programming)

and [https://github.com/Kango/Processing-snippets/wiki/Variables,-Arrays-and-object-oriented-programming](https://github.com/Kango/Processing-snippets/wiki/Variables,-Arrays-and-object-oriented-programming)

and [https://www.processing.org/tutorials/objects/](https://www.processing.org/tutorials/objects/)

Chrisir

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 30, 2020, 5:16pm UTC](https://discourse.processing.org/t/thinking-object-oriented/17448/5 "2020-01-30T17:16:07Z")

</div>

> **[r/processing - Help with OOP and using classes.](https://www.reddit.com/r/processing/comments/ew5nmy/help_with_oop_and_using_classes/)**
>
> 3 votes and 6 comments so far on Reddit
