Sign in to follow this  
Orymus3

"New" to OOP

Recommended Posts

Orymus3    18821

Hi,

 

In 'real life' I'm a manager, part time designer in the video game industry. That's all fun and all, but the truth is, I'm an indie at heart.

In my journey to becoming a full-fledged indie by my mid 30s, I've recently started programming "again".

 

Long story short, I've been 'programming' runtime since I was 9, in various languages with limited success.

Spent a year studying computer sciences and dropped out despite keeping my score above 90% (I was obsessed with Game Design back then...)

Nowadays, I find myself using a number of API, namely Dart.

While I still understand algorithmic, and can relatively learn to adapt to syntax, I find myself faced with a very difficult wall: Object-Oriented Programming.

 

I'm not exactly estranged to the idea of Object-Oriented Programming, I've already used Visual Basic to some degree.

But the big bad and ugly truth is that I still 'think' in terms of Runtime, and somehow reason things through that way, which appears to limit me in adapting to OOP.

I've come to the conclusion that I need to start from scratch so that I really understand what I'm doing, and the way to go is to understand the logic of OOP.

I've looked up the Wikipedia articles on OOP, and they've helped, to a degree, but I can't help but figure there must be a more appropriate guide to OOP out there, so that I can modernise my knowledge and finally adapt to that way of thinking.

 

Anybody here knows of such an article/book?

I looked trough the FAQ stickies around here to no avail.

 

(Found: http://www.gamedev.net/page/resources/_/technical/game-programming/object-oriented-game-design-r3116 but this is C++ only)

Edited by Orymus3

Share this post


Link to post
Share on other sites
Orymus3    18821


To be honest, I'm not understanding this part of your post.

 

Well, before OOP, programming (as I knew it) was a lot of lines, individual variables, etc.

In other words, I can't fully take advantage of classes, objects and instancing because I'm finding it very hard to fully understand the underlying logic.

 

The fact that I struggle against many aspects of OOP has led me to believe that there is an inherent problem: I do not understand OOP as much as I believed I did. Just because I can reference an object.method() with proper syntax doesn't mean I can fully leverage the advantage of OOP way of thinking, and this is the issue I'm faced with. Without proper understanding of the concept of OOP, I'm not really using OOP.

Share this post


Link to post
Share on other sites
Nicholas Kong    1535

I think OP seems to be referring to procedural programming. He programmed in Visual Basic before.

 

To understand Object Oriented Programming is to relate to real life. You can think of yourself as an object. You have some methods or behavior that you possess. You have the eat() method and sleep() method etc. You have several fields or variables associated with you. You have the age variable = 30 represented by an integer. You are an instance or an example of the Human Class. biggrin.png

 

Try applying this concept in an object oriented language. The fact that you do not understand now does not mean you will not understand later. Take the time to learn it properly. I think you are beating yourself up.

Edited by warnexus

Share this post


Link to post
Share on other sites
Orymus3    18821

Warnexus, yes I do understand at least that. I also understand how superclass can have children that will inherit all methods and properties (extending).

Taking this simplified theory to actual practice is where I'm having troubles.

 

For example, if I want to design a map system with enemies on it, I'll instantly think of making an array for the map coordinates along with an array that contains all game objects, etc. Unless forced, I will not naturally think in terms of 'objects' & 'classes' because, while I believe I understand the underlying theory, I'm having a rough time applying it in context and leveraging it efficiently.

 

One thing I'd like to do is to code pong in a non-procedural way for example, but I'm having a hard time architecturing my concepts in terms of classes and objects. I can code allright, but I can't think in terms of how it needs to be built if it is to be OOP.

 

Is it any clearer? (its hard to talk about things I only half grasp)

Share this post


Link to post
Share on other sites
Nicholas Kong    1535

Warnexus, yes I do understand at least that. I also understand how superclass can have children that will inherit all methods and properties (extending).

Taking this simplified theory to actual practice is where I'm having troubles.

 

For example, if I want to design a map system with enemies on it, I'll instantly think of making an array for the map coordinates along with an array that contains all game objects, etc. Unless forced, I will not naturally think in terms of 'objects' & 'classes' because, while I believe I understand the underlying theory, I'm having a rough time applying it in context and leveraging it efficiently.

 

One thing I'd like to do is to code pong in a non-procedural way for example, but I'm having a hard time architecturing my concepts in terms of classes and objects. I can code allright, but I can't think in terms of how it needs to be built if it is to be OOP.

 

Is it any clearer? (its hard to talk about things I only half grasp)

The point of a class is for re-using code which prevents duplicated code and allows for reusability of this class in other projects.

Before jumping ahead to code up the game, take paper and a pencil and think about the general things that are going to be in the game.

 

Below is one way to structure Pong. Most of the classes besides the two classes: paddle and ball can be used in future game projects. Code is in Java.  biggrin.png

 

In a pong game, there are two paddle objects. So both paddle object will inherit from the same class Paddle.

 

 

Paddle playerOne = new Paddle(x,y);

Paddle playerTwo = new Paddle(x,y);

public class Game extends Canvas
{
 
}
public class Vector2D
{
 
private double x;
private double y;
}
public class Ball extends Sprite
{
 
}
// this paddle object will inherit from the class Sprite
public class Paddle extends Sprite
{

private Vector2D position;
private Vector2D velocity;
 
public void draw(Graphics g)
{
 
}
 
public void update(long milliseconds)
{
 
}
 
}
public class Sprite implements GameObjects
{
 
public void draw(Graphics g)
{
 
}
 
 
public void update(long milliseconds)
{
 
}
 
}
public interface GameObjects
{
 
public void draw(Graphics g)
{
 
}
 
public void update(long milliseconds)
{
 
}
 
}
Edited by warnexus

Share this post


Link to post
Share on other sites
patrrr    1323

 

Warnexus, yes I do understand at least that. I also understand how superclass can have children that will inherit all methods and properties (extending).

Taking this simplified theory to actual practice is where I'm having troubles.

 

For example, if I want to design a map system with enemies on it, I'll instantly think of making an array for the map coordinates along with an array that contains all game objects, etc. Unless forced, I will not naturally think in terms of 'objects' & 'classes' because, while I believe I understand the underlying theory, I'm having a rough time applying it in context and leveraging it efficiently.

 

One thing I'd like to do is to code pong in a non-procedural way for example, but I'm having a hard time architecturing my concepts in terms of classes and objects. I can code allright, but I can't think in terms of how it needs to be built if it is to be OOP.

 

Is it any clearer? (its hard to talk about things I only half grasp)

The point of a class is for re-using code which prevents duplicated code and allows for reusability of this class in other projects.

Before jumping ahead to code up the game, take paper and a pencil and think about the general things that are going to be in the game.

 

 

I don't think the major point of classes is really re-use; they're great for re-use of classes, but that's a truism. Often though, you have a pattern of accessing an already existing object and want to reuse that pattern, so you use a function. Functions aren't part of the generic "class" definition but have been added to Java's classes because they are so useful for re-use.

I would say that the point of classes is that their way of describing encapsulation is easy to understand and that their invariants are easy for the environments to enforce, making development more stable due to fewer variables.

Edited by patrrr

Share this post


Link to post
Share on other sites
dave j    681

it also helps to use a language that forces you to stay in OOP land such as Java and C#.


I found this. When I first started learning OOP I was trying to do it in C++ having been a very competent C programmer for years. I could never stop automatically thinking of solutions in C. I switched to Smalltalk and all soon became clear. You're probably better off with something like Java today - it wasn't around when I first tried OOP.

Share this post


Link to post
Share on other sites
SuperG    1300

OOP well the way I have read about it. Code reuse is common practice. So even in C you got function libraries. Might be that code reuse is made lot easier with OOP.

But I think it more a way to handle large software solution more practical. With a highlevel of view by its objects. So devide it in manageable components wich are decoupled as much possible. with it software solution becomes easier manageable and extensible. Also it seams you could do it the right way but also wrong.  I suppose there is some skills involved to choose your classes right and depend also on the task at hand. So doing the OOAD right needs also some experience.

 

C++ Got to much pitfalls so Java or C# seams a good start on learning OOP

Share this post


Link to post
Share on other sites
Orymus3    18821


You might also try Object Mentor's pdf's, which give an excellent overview of some of the principles of OO design.

Yes, it was my next 'go-to' as it was part of the article's bibliography!

Thanks for referencing it regardless.

 

Also, I have to go with Dart for now, but I'll try to apply what I've read about encapsulation, abstraction, inheritance and polymorphism (I assume a lot of this comes with practice anyway). At least I have some ground theory to work from, so its better than learning by mimicking other people's code to achieve OOP results.

 

Thanks all!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this