object oriented design using procedural programming?

Started by
22 comments, last by GameDev.net 18 years, 1 month ago
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.
Advertisement
That's not OOP at all.
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..




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?
What does your program DO? What is a 'ClassA'?
Compare and constrast. Oh, and also read. :)
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.
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...
You're above code shows no signs of OOP. but thats just my thoughts..
Hello?
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.

This topic is closed to new replies.

Advertisement