OOP and Structured programming approach | Sololearn: Learn to code for FREE!

+66

OOP and Structured programming approach

How to decide that in which situation to use Object oriented programming approach and in which situation to use Structured programming approach ? Any help will be appreciated.

5/21/2018 6:16:58 PM

Rstar

51 Answers

New Answer

+59

In some Contexts you have naturally a lot of objects like buttons in gui design for example or vectors in math or game objects in games. It makes sense to use object oriented Programming in those contexts. Try to think about the relationships between objects in your program often times it makes sense to try to model them using inheritance and other object oriented features. But sometimes there is not much going on in your program with regards to objects,like if you make a calculation so you should try to think more in regards to how you can break the problem in small reusable parts. Often times you need both, if I want to make an calculation using vectors I break it down to different functions but they use the object(vectors) to simplify the code(in this example I don‘t need a variable per vector per dimension)

+19

If you are building real world applications like football game use oops, if you are building software that is for some hardware like for processor or microcontroller use Structured programming.

+17

C++ Soldier (Babak) Normally, I try to follow good programming practices, so most of the rules aren't mine. I like to write stuff so that it is easy to read and in short functions. And I completely agree that fun is important. I read already several "medium big ass" guidelines and liked 90 percent of what they contained... and also followed 95 or so. Amway, OOP basically was out off the question, because they have been for C and DXL (Doors Extension Language) which basically deals with objects, but isn't really to program object oriented...

+16

C++ Soldier (Babak) I also have the feeling that I'm somewhat off topic. It wasn't my intention to sidetrack the discussion. It's more like to state that I think that it can be also an option to use both oop and sp together...

+15

C++ Soldier (Babak) I'm afraid that I'm actually old school. printf just seemed like the best choice. I chose it also so that the languages can be compared and not the techniques, which is actually a good idea to add. Would you be so nice and write Bonus in an object oriented way? The rule is basically that the output is exactly the same as all the others in the SameSame section. https://code.sololearn.com/WfpY4zqBx9yk/?ref=app

+13

structured programming gives more preference to functions and control flow. and global data can be used by any functions . so it is hard to do debugging and object oriented programming gives more preference to data we can made data private or public . so it helps in debugging and maintaibility in large programs plus oop adds a few more new features like ingeritance which are useful

+12

I'm just making quite short programs. For some reason I end up doing structural programming in an object-oriented language. Basically it's like both techniques combined if you look at the complete code executed. On the top there is structural organized code but by far the majority of code at the lower level is object-oriented... I might be completely wrong but I don't really see any big problem by mixing both techniques together in a single program.

+9

Thanks to KrOW && David Gablinger for providing a good discussion model about this multi-aspect subject here. As a silly yet interesting story of how I was thinking about OOP, around 2 years ago, even though I naively knew that OOP is a gold standard for working on large-scale/industry-scale projects and what would be the benefits of using it even for small projects of mine, I was stubbornly sticking with my rusty gun and convincing myself that functional/procedural/modular/etc. paradigm is the only conceivable scenario for my implementations. Actually, the root of this conflict was a psychological matter of how I confined myself to a certain way of thinking without even knowing how other approaches work (as a direct consequence of just knowing little of every thing and judging based on false evidences). Yeah, that's the story of many people and that's called experience! ;D

+9

Modi OOP is out of the question?! Well... I guess you right, then. Using printf in cpp source file whispered in my ear that you like old-school ways to deal with problems. As I mentioned you are free to come up with all kinds of flowery ideas to shape your program when you working alone or operating your business independently, otherwise you need to return to your drawing board and add some missing elements which might be costly.

+8

If ur going to use GUI do oop. If not do structure.

+8

Obviously there's no definite guideline for that matter and making decision which one goes into your final design and implementation comes with experience, nature of the system, requirement criteria, and other factors that you can learn about them in software engineering materials. Chances are, you've been involved in some long ass coding sessions which exceeds 1000 lines of code using structured style programming and all of sudden you found yourself doing 10 hours of fruitless debugging with splitting headach to find an annoying bug which every time you hit the run button turns to a big fuck you from the compiler to your effort! Then you come up with a solution. Yes, OOP. That's why Bjarne stroustrup and other good folks busted their asses to make our labors less nerve wracking. So yeah, OOP is good but not a silver bullet. Also good old structured programming paradigm is also come to worth sometimes and I love it too. ;)

+7

For projects many people are working on, OOP is more efficient and also for later improvements it's more comfortable, because the classes make it easier to change some code without affecting the other code. Procedural programming is closer to the processor's functioning and may result in more efficient machine code.

+7

In my humble opinion, I'm not sure, but I think that structural programming is used to make an easier task which little dependency in its variables while in the OOP you are looking for a simplicity at the time of expands features of objects or classes you have created. One example of structural programming is whatever maths task, in the other side, we have to make a timetable for the employees in a factory, and then we need to create one class for employees and then we will adding features like days on holidays, days in weekend, free days, worked hours in laborables days, and and so on.

+7

Modi In fact there's no right or wrong way to find a solution to a problem at hand as long as you work on your own (Ironically, you are rule. Not recommended by gurus but yeah you can do it anyway!) and the code produces your desired results. Formal projects are different stories. Everything MUST BE followed according to MIGHTY ass guideline and it's completely different from our playful style programming. That's not so horrible as it sounds, really, since by following them you develop some good coding habit, but as everything in life it take sometimes to get used to it. Have fun ;D

+7

Modi I wonder why you didn't get the point of this discussion. Please, take your time and absorb the real intention of the whole thing. BTW, I will be happy to make a contribution to your experiment.

+6

I see OOP use like an way to abstract your problem... This mean that like any abstraction, it hide something to you and this can be good or bad... Think about polymorphism... It its really useful for hold your code (and you architecture) more clean but it has a cost (small but this its relative) in power and memory terms.. Any abstraction has one cost, nothing its free... I know this is not related to software architecure but using it for tell something. I want tell that all its relative to your context (like language used), to your preferences (most hate OOP while other write anything like an objects) and your problem (develop an gestional its different from develop an interpreter). OOP its really good for me but i admit that its easy abuse of it making it counter productive and it make you think more about the "what" you want solve than "how" you solve it... At end: dont exist a perfect way to do anything, so its in programming, so its on life

+6

To elaborate with a made up example: say you do an engineering/physics calculation and you have 3-dim vectors for speed and position. Then with structured programming it could happen that you confuse speed and position. With the classes speed and position you could make sure this never happens, and also allow for a more natural language when using those objects

+5

Shekhar Ranjan If you are passionate about that, then learn all of them and of course experiment with them. The more you learn, the better your choice will be for picking the proper one. Try to read a software engineering book if you have time. it'll definitely expands your horizon. ;)

+4

Depending on the project you are going to make, I believe that by studying the first languages you can improve your skills for the following.

+4

Disregard both, use Functional Programming and transcend humanity. (I'm joking, but FP is still great when it finally clicks. Try it)