Object Oriented Programming vs Structural Programming

  • Thread starter fog37
  • Start date
  • #26
FactChecker
Science Advisor
Gold Member
5,699
2,109
The mechanism discussed above is called function or method overloading, and pertains to C++, C#, Java, and possibly other languages. It does not pertain to C.
Good point. And I am not sure that it is really part of OOP or just a common feature of more modern languages.
 
  • #27
rcgldr
Homework Helper
8,697
528
specific functions with the same name but with different parameter lists can be distinguished from each other.
In the case of C++, this is usually accomplished by changing the internal function names to include parameter information, known as name mangling. A similar thing was done for legacy 16 bit X86 C compilers, where the actual library function names in a C source file were modified depending on the model (tiny, small, medium, large, huge). However, assembly code had to use the actual modified function names.

https://en.wikipedia.org/wiki/Name_mangling

Getting back to OOP, there's the option of using a static member function when dealing with two (or more) objects, such as a compare function. Assume there is a class named xmpl_class, and two objects, xmpl_class a, b. If the compare function is non-static, the usage would be a.compare(b) or b.compare(a). If the compare function is static, the usage would be xmpl_class::compare(a,b). There are also static member variables, which other than syntax, are similar to regular static variables.

There's another type of programming, which I call associative which is similar to declarative, dating back to the days of plug board programming and the language RPG II which was derived from plug board programming. Actual plug board systems used card readers and line printers, RPG II could also use files. Most of the programming defined links between input fields and formatted output fields or a limited set of math functions, where an input field would be linked to a partial or total summation function. The order of operations was not defined (in the case of plug boards, it's just a bunch of wires, which in theory could have allowed all of those operations to occur in parallel).

https://en.wikipedia.org/wiki/Plugboard

https://en.wikipedia.org/wiki/IBM_RPG_II
 
Last edited:
  • Like
Likes FactChecker
  • #28
1,001
57
In OOP, when we see an instruction like Servo myservo, the word myservo is an arbitrary name given to the object (an instance of the class) while Servo is the class itself, correct? The line of code Servo myservo creates the object.
On the other hand, I believe that commands like myservo.attach(pin) and myservo.write() are methods contained in the Servo library that are used by the object myservo, correct? So when we see two words separated by a period, the first is the object and the second is the method. As an other example, the command serial.begin() used to initiate serial communication: the method is begin which is used by the object serial. The object serial is an instance of a certain class...
 
  • #29
33,721
5,418
In OOP, when we see an instruction like Servo myservo, the word myservo is an arbitrary name given to the object (an instance of the class) while Servo is the class itself, correct?
Yes
fog37 said:
The line of code Servo myservo creates the object.
On the other hand, I believe that commands like myservo.attach(pin) and myservo.write() are methods contained in the Servo library that are used by the object myservo, correct?
Yes, although I wouldn't call Servo a library. Servo is a class that exposes the write() and attach() methods, and whatever other methods that are defined on the Servo class.
fog37 said:
So when we see two words separated by a period, the first is the object and the second is the method.
It doesn't have to be a method. A public property or field can also be accessed this way.
fog37 said:
As an other example, the command serial.begin() used to initiate serial communication: the method is begin which is used by the object serial. The object serial is an instance of a certain class...
 
  • Like
Likes FactChecker
  • #30
phinds
Science Advisor
Insights Author
Gold Member
2019 Award
16,223
6,292
Syntax depends on the language. In VB, you would expect to see something like:

Public myControlArray As classLabelArray

Where classLabelArray is a defined class and the statement makes myControlArray in instance of the class. In VB, a raw statment like

classLabelArray myControlArray

Would be gibberish.
 
  • #31
1,001
57
Thank you. You are right. I guess I was my question was implicitly referring to the Java language...
 
  • #32
harborsparrow
Gold Member
536
108
"The line of code Servo myservo creates the object."

I think the above statement is not precisely accurate. "Servo myservo" declares the name-and-type of an object that the programmer intends to use subsequently. Actually to create (i.e., allocate memory for) the object requires an assignment statement, such as "myservo = new Servo".
 
  • Like
Likes QuantumQuest and Chestermiller
  • #33
1
1
OOP reflects the real world behavior of how things work. It is important because
  • It make visualization easier because it is closest to real world scenarios.
  • You can reuse the code, this saves time, and shrinks your project.
  • Once you know the concept, it makes you a cooler coder among your friends ;) .
There are 3 basic features of object oriented programming language:
  • Inheritance
  • Polymorphism
  • Encapsulation
By using these features you can easily reuse your program or part of your program. Object oriented programming provides you a power to do programming in a very effective manner. Learn OOP concept and implement it in your daily programs.
 
  • Like
Likes FactChecker

Related Threads on Object Oriented Programming vs Structural Programming

  • Last Post
Replies
10
Views
900
  • Last Post
Replies
11
Views
3K
  • Last Post
Replies
2
Views
6K
Replies
17
Views
923
  • Last Post
Replies
2
Views
2K
Replies
11
Views
1K
Replies
3
Views
12K
Top