Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


"New" to OOP


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Orymus3   Crossbones+   -  Reputation: 10706

Like
2Likes
Like

Posted 27 July 2013 - 01:37 PM

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, 27 July 2013 - 01:42 PM.


Sponsor:

#2 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 27 July 2013 - 01:46 PM

But the big bad and ugly truth is that I still 'think' in terms of Runtime,

 

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


Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#3 Orymus3   Crossbones+   -  Reputation: 10706

Like
0Likes
Like

Posted 27 July 2013 - 01:55 PM


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.



#4 warnexus   Prime Members   -  Reputation: 1505

Like
2Likes
Like

Posted 27 July 2013 - 02:50 PM

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, 27 July 2013 - 02:53 PM.


#5 Orymus3   Crossbones+   -  Reputation: 10706

Like
0Likes
Like

Posted 27 July 2013 - 03:15 PM

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)



#6 warnexus   Prime Members   -  Reputation: 1505

Like
2Likes
Like

Posted 27 July 2013 - 05:45 PM

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, 27 July 2013 - 05:57 PM.


#7 Orymus3   Crossbones+   -  Reputation: 10706

Like
2Likes
Like

Posted 27 July 2013 - 07:08 PM

Thanks for the input.

 

Also, I was lucky to find this article which is pretty much what I was looking for.

 

Thanks again!



#8 warnexus   Prime Members   -  Reputation: 1505

Like
1Likes
Like

Posted 27 July 2013 - 07:56 PM

Thanks for the input.

 

Also, I was lucky to find this article which is pretty much what I was looking for.

 

Thanks again!

Ah yes that is an awesome article!



#9 jbadams   Senior Staff   -  Reputation: 19453

Like
2Likes
Like

Posted 28 July 2013 - 12:12 AM

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



#10 kunos   Crossbones+   -  Reputation: 2207

Like
1Likes
Like

Posted 28 July 2013 - 01:17 AM

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


Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#11 patrrr   Members   -  Reputation: 1054

Like
1Likes
Like

Posted 28 July 2013 - 02:17 AM

 

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, 28 July 2013 - 02:19 AM.


#12 dave j   Members   -  Reputation: 599

Like
1Likes
Like

Posted 28 July 2013 - 04:50 AM

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.

#13 SuperG   Members   -  Reputation: 569

Like
1Likes
Like

Posted 28 July 2013 - 09:40 AM

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



#14 Orymus3   Crossbones+   -  Reputation: 10706

Like
0Likes
Like

Posted 28 July 2013 - 01:17 PM


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!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS