Object Oriented Programming vs Structural Programming

  • Thread starter fog37
  • Start date

FactChecker

Science Advisor
Gold Member
2018 Award
4,719
1,613
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.
 

rcgldr

Homework Helper
8,546
461
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:
800
36
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...
 
32,344
4,130
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...
 
14,873
4,545
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.
 
800
36
Thank you. You are right. I guess I was my question was implicitly referring to the Java language...
 

harborsparrow

Gold Member
523
102
"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".
 

Want to reply to this thread?

"Object Oriented Programming vs Structural Programming" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top