Jump to content
  • Advertisement
Sign in to follow this  
Tradone

object oriented design using procedural programming?

This topic is 4478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Thank you. I think I have fully grasped the concepts of object oriented programming through this forum. I like to give a thank you to all the moderators, and members who have answsered my questions with such sincerity. Here's my story. I have developed a code using the procedural style through out my first 8 months of programming history. The code totaled out to be somewhere around 8000 lines, in one cpp file. As I carefully analyzed my code today, I have noticed that I was grouping my code by similar types. Now that I understand the concepts of oop, I have noticed that my procedural style was somewhat evolving the way to oop. But through this experience with procedural style, I have noticed that one can reach somewhat an object oriented approach using the procedural programming. ex)
main(){
input[256][2];
type=get_type();

if ( type == 1 || type == 2 || type == 3 ){
  //do for all 3 types
  code;
  code;

  //do for only type 1
  if( type == 1 ){
    code;
  }

  //do for only type 2&3
  if( type == 2 || type == 3 ){
    code;
  }

  //do for only type 1&3
  if( type == 1 || type == 3 ){
    code;
  }

  //if type is 1, also perform what is inside type 4
  if( type == 1 ){
    type = 4;
  }
}

if ( type == 4 || type == 5 || type == 6 ){
  //do for all 3 types

  //do for only type 4

  //do for only type 4&5

  //do for only type 4&6
}

and the list goes on.

}



Is this somewhat an object oriented design? well, I am completely switching all my functions to classes, but want to know the limitations of my previous styles.

Share this post


Link to post
Share on other sites
Advertisement
that's not opp?
not even close?
grouping into similar types?

hm... i guess i am still not grasping the concepts of opp...
I am redesigning my thing...

I thought there was some weak concepts inheritence ( the type structure has some sort of inheritence )
heirarchy would be like
class A
|
|-type 1
|-type 2
|-type 3 ( can later type 3 wil be transfered to type 4 thus isn't this kinda multiple inheritence?

class B
|
|-type 4
|-type 5
|-type 6

perhaps not..




Share this post


Link to post
Share on other sites
okay, maybe my program can not be written in object oriented?

come to think of it, my program is based on a dynamic input of a specific action such as delete, modify, or add.

when added, it saved into file.
when modified, it modifies.
when deleted, it deletes.

what would be the objects in this scenario?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What does your program DO? What is a 'ClassA'?

Share this post


Link to post
Share on other sites
class A was just an example.

complicated thing explained simple...
my program receives an input from a user to either delete, modify, or add something to a database.
and whatever information that is stored in the database, it is saved in file.
later that file can be deleted. kind of like a word processor in a way.

thus it is based on actions by the user.
and object oriented is like the opposite of action orientated...

well there's more to this.. such as list and search.
so i grouped them into 3 categories

1) list, search.
what is in common: they both lists, except for search certain things are filtered.

2) write, modify
they both need to use i/o. the only difference is that modify will override the existing file, so in a modify, the file name must be specified.

3) delete
just delete the file.

now it is a bit more complex than this, but that's about what there is..
for example, the list is dynamically created by a certain language that i made, and depending on the source of that new language, it must do certain things, thus must be tokenized and parsed.
Now this new language has options such as simple adding, subtracting, concatenating strings, number/string comparisons, if clauses, loops, and some other functions.

Now I've already made this to fully function with almost minimal errors, for I have been testing and debugging my procedural source code for 8 months now. But the source code was extremely repetitive and disorganized. While I was looking into object orientated programming I thought this would solve the solution of "path finding" kind of thing, because my actions are based on path finding, and fitting into certain types. such as the list, write, delete types.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Compare and constrast. Oh, and also read. :)


Zahlman thanks for the link.
the reason I'm changing all my code is because of the third link.
Hopefully I can fix that, but this is going to be my frist object oriented project, so I'm kinda nervous.

and I don't think I can quite understand the internal / external polymorphisms just yet because I don't understand internal polymorphisms completely for I have never coded in oop style.

but back to the original question, my code above does show some signs of oop. no? want to know if I am understanding oop correctly...

Share this post


Link to post
Share on other sites
Quote:
Original post by cherryhouse
You're above code shows no signs of OOP. but thats just my thoughts..


yea! no problemo!
but now I'm almost done brainstorming for my new implementation.
i'll post it up soon.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!