Structured and object oriented programming

Discussion in 'Programmer's Corner' started by Parth786, Feb 17, 2018.

  1. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    A programming language is set of instruction written for a machine. Programming languages are designed to make it easy for humans to write complex instructions. we write statement and function in programming language. Structured programming and object oriented programming used in computer science , they are both useful to programmers.

    I started reading about structured and object oriented programming but I am confuse I don't understand meaning of structured and object oriented programming. I am looking help to understand difference between structured and object oriented in programming. I saw this link helpful https://en.wikibooks.org/wiki/The_C...ng/Object_Oriented_vs._Structured_programming but still confuse

    Please help me to understand the use of Structured programming and object oriented programming in real world..
     
  2. ericgibbs

    Moderator

    Jan 29, 2010
    7,663
    1,545
  3. MrChips

    Moderator

    Oct 2, 2009
    18,448
    5,848
    It is not a question of Structured Programming (SP) vs Object-Oriented Programming (OOP).

    OOP is layered on top of SP.
    SP is fundamental. OOP is an extension of SP, in the same way C++ is an extension of C.

    OOP takes the philosophy of modularity and reusable code two steps forward.
    OOP is based on the concept of encapsulation, properties and methods, classes, and inheritance.
    OOP is based on the concept of actors or objects, belonging to a class and having common properties and behaviors. These properties and behaviours can be inherited from "parent" objects and propagated to "child" objects, hence "inheritance".
    The OOP paradigm is that of independent autonomous objects and classes which can be reused and called into action without having to reinvent every new object.

    For example, look at your browser screen. How many different types of action buttons do you see on one widow? Imagine if you had to write the code for each and every one of those buttons. Instead, you can create one class of objects called "button" and call the same code for all the different buttons. Each button has a different style, colour, location, label, and function. Yet, we can create a single set of properties and methods for all buttons.

    Summary, you can use Object-Oriented Programming to make programming easier. Structured Programming fundamentals still remain useful and valid.
     
    xox and Parth786 like this.
  4. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    5,697
    6,382
    You can use the principles of Structured and Object-Oriented Programming in any language include Assembly. (if that trips your trigger)

    In C the usage of data structures with pointers to data and functions (procedures) allow for the abstraction of limited Object-Oriented lite Programming. For most embedded projects you don't need the full C++ language.
    https://www.state-machine.com/doc/AN_OOP_in_C.pdf

    Some of these OOP methods were used in the interface software for this projects software. We have different display/control methods for different motor and unit types but only one function call to handle them all.
    https://forum.allaboutcircuits.com/threads/mandm.75507/

    Code (C):
    1.  
    2. // code fragments
    3. typedef void (*display_func)(void);
    4.  
    5. struct modetype {
    6.     volatile uint8_t demos, move, free, operate, demos_init, slow, emo, v24, cal, on_off_only, idle, locked, info_only, qei, slow_bypass, change;
    7.     display_func display;
    8. };
    9. volatile struct modetype mode = {FALSE, TRUE, TRUE, HELP_M, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE};
    10.  
    11. // program default mode.display
    12. void default_display(void)
    13. {
    14. // display code
    15. }
    16.  
    17. // another possible LCD display function for the mode.display
    18. void emo_display(void)
    19. { // System has detected a condition that caused it to stop in a safe comdition
    20.     sprintf(bootstr2, " EMO EMO EMO EMO      ");
    21.     LCD_VC_puts(VC0, DS1, YES);
    22.     sprintf(bootstr2, " Power Cycle/Reset    "); // info display data
    23.     LCD_VC_puts(VC0, DS2, YES);
    24.     sprintf(bootstr2, " Assy Wiring Short?   "); // info display data
    25.     LCD_VC_puts(VC0, DS3, YES);
    26. }
    27.  
    28. mode.display = default_display; // display screen function pointer
    29.  
    30. void nav_menu(void) // call the correct screen display function
    31. {
    32.     Set_Cursor();
    33.     mode.display();
    34. }
    35.  
    Set_Cursor configures the mode 'object' global data then mode.display executes the mode 'object' code.
     
    xox and JohnInTX like this.
  5. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    @MrChips @nsaspook Sorry but still I don't understand what is class and object in programming.

    I have installed IDE for C and Java programming in my computer. I can write program in C language. I don't have much knowledge on java programming. I can run the program on eclipse

    java1.jpg

    Can we go through any program to understand what is the difference between object class and structure. In c program structure is used to store multiple type of data like int , char.

    If we take a simple example, it will help me more
     
  6. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    5,697
    6,382
    It's time for you to hit the books again on both C and programming in general.
     
    Brian Griffin likes this.
  7. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    Yes, I am doing this. I am studying book for c programming. at the starting of book on the 4th page. there is description about structured and object oriented programming but there is not much description. I spend some time on google and I found the bunch of materials but I did not understand it the real meaning.
     
  8. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    5,697
    6,382
    Sure, you want to fly without learning how to walk, it's a familiar tale.

    http://www.compileonline.com/index.htm
     
    Brian Griffin, spinnaker and JohnInTX like this.
  9. MrChips

    Moderator

    Oct 2, 2009
    18,448
    5,848
    Let's be honest. You are not ready yet for object oriented programming.
    You are not ready yet for advanced topics such as structures in C.
    You still have not mastered basic algorithm design and control structures.
    You still need to work on pointers, interrupts, timers, semaphores, multi-tasking, scheduling, etc.
     
    JohnInTX likes this.
  10. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    I am totally agree with your statement's, this chapter was in C programming book at starting. I think I should just leave this chapter and I should focus on next chapters
     
    nsaspook likes this.
  11. JohnInTX

    Moderator

    Jun 26, 2012
    3,616
    1,859
    Adding to the others' and what you posted while I was typing, it's common in the opening pages of a book to have a broad overview of the subject. It doesn't mean that you have to master the topics just because they are mentioned to proceed. Just get on with the simple examples in the book, learn the concepts taught by those examples and, when you know them, move on to the next topic.

    Reading and participating in your many threads (and our PMs) shows that you unfortunately haven't learned the lessons that many here have tried to teach including start simple, stay focused, and master concepts before moving on to something else. That's important because complex concepts build upon simple ones and if you haven't mastered the simple ones any hope of understanding more complex concepts will end in failure. Yesterday it was receiving GPS strings on a UART, today it's a survey of software design methods. Tomorrow is anybody's guess.

    None of us are trying to scold you here but you continue to have trouble in your programming efforts because of the way you approach problems. As you've been told many times by many experienced members here and elsewhere, until you change your approach you'll continue to have problems.

    Just trying to help you.
     
    Brian Griffin, nsaspook and ericgibbs like this.
  12. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    7,815
    3,663
    How is it possible to graduate from any engineering school today and not at least have a very basic knowledge of OOP? I would think even the most basic engineering curriculum would have at least some Java or C++ programming.
     
  13. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    I am working together on both C and embedded C programming. I am doing practice writing code on PC. I am practicing to solve some tough C examples. I don't say I am good at programming but I can say I am doing batter the before. I think I am not too bad who can't start to write embedded programming. As you can see I have been writing embedded program for LED, Switch, Push button, DC Motor, LCD, IR sensor.. I know it's not enough. I posted GPS thread 16 day's ago and I was asking about the GPS and working of It. I had knowledge of Uart and interrupt program I knew both are important for GPS interfacing so I tried to understand about GPS programming. I have some issues there I though I should try myself. defiantly I will come back on that thread

    You can blame me that I was not serious or bad education system. It's up to you. I can not change what has been happened but I can try my best for improving skills and I am doing it.
     
    Last edited: Feb 17, 2018
  14. WBahn

    Moderator

    Mar 31, 2012
    24,070
    7,471
    I doubt there are many engineering curricula that don't require programming to some degree, but I imagine there are still quite a few around that don't require object-oriented programming.
     
    Brian Griffin likes this.
  15. WBahn

    Moderator

    Mar 31, 2012
    24,070
    7,471
    Once again I would recommend to you the Nand2Tetris project. You will learn how objects are implemented and how the functions that operate on them are accessed from the object.

    As has already been pointed out, structured programming and object-oriented programming are not two different alternative. Structured program is simply programming using a small set of well-defined control structures -- namely sequences, selections, and iteration constructs. The big thing is that you do NOT use goto statements for controlling the logical flow of your program. Object-oriented programming is just a further refinement on structured programming in which access to much of the code is restricted so that it is difficult to call functions from places where calls to those functions is all but guaranteed to be a logical error and to make it difficult for functions to act on data other than the right kind of data for that function. Through discipline you can write code that is very object-oriented-like even in a language that is not (such as C) and you can write programs that are structured-like even in a language that is not (such as assembly). Since this is transitive, that means that you can write object-oriented-like programs even in non-structured languages. What structured languages do is make it easy to write structured programs and hard to write non-structured programs. What object-oriented languages do is make it easy to write object-oriented programs and hard to write non-object-oriented programs.
     
  16. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    5,697
    6,382
    When most people hear OOP they think about computer languages or programming but the motivation of using OOP in a project is something else. It's a method of analytical reasoning central to engineering in general.

     
    JohnInTX likes this.
  17. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    7,815
    3,663
    Why don't you go back to school then? Here we can "monitor" a class. You get the same thing all of the other class members get but there is no degree. It can be cheaper than a degreed course.
     
    JohnInTX likes this.
  18. JohnInTX

    Moderator

    Jun 26, 2012
    3,616
    1,859
    That’s a really good idea. You might not be able to audit courses at a local university but check out Acedemic Earth. They link to courses from places lice Stanford and MIT among others. Free.
    https://en.wikipedia.org/wiki/Academic_Earth
     
  19. Brian Griffin

    Active Member

    May 17, 2013
    63
    28
    What I remembered during my college days, the C++ course I had was only half-semester. It went together with the Autocad class, which was the other half of the semester. Not all engineering syllabuses and schools include OOP inside, but I wish it was though.

    In where I stay, there are quite limited schools teaching C/C++ or Java. Most of them are about HTML or some webpage programming course.
     
  20. Parth786

    Thread Starter Active Member

    Jun 19, 2017
    642
    45
    I have read all those projects on this site http://nand2tetris.org/course.php There have been explained in very simple way to understand the basic of computer architecture but there is no information for c language. I am not become expert but I am trying my best

    I have some financial issues. I took the three month's class for embedded system but I didn't learn more because I had many doubt during the 2 hour's lecture. There was 60 student in class There was few time to ask questions So I could clear only few doubt's.

    The best thing is that I have not given up. I have confidence in myself that I can learn programming. I like to read about embedded system and programming. I am doing my best at every day. I am not saying that I am victim I know I have done so many mistakes but I have learned a lot from mistake. I don't know what you think about my performance but I am feeling good because I think I am batter then before. I just need a good planning.I am not be afraid to work hard. My mistake is that I do not ask the right questions at the right time. I think I should work more on this.
     
    Last edited: Feb 17, 2018
    JohnInTX likes this.
Loading...