What are the Concepts of Object-Oriented Programming?

  • Thread starter Thread starter Passionate Eng
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary

Discussion Overview

The discussion revolves around the concepts of object-oriented programming (OOP), specifically focusing on definitions and examples of instances, objects, methods, and interfaces. Participants express a need for clarity on these terms and seek sample code, particularly in Java, to illustrate these concepts.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant expresses confusion about the terms instance, object, method, and interface, requesting labeled sample code in Java.
  • Another participant suggests that understanding the definitions of these terms is more important than having labeled code.
  • A participant explains that a class is a user-defined type and that an object or instance is a variable of that class type, with memory allocated for data members.
  • Methods are described as function members of a class, while interfaces are defined as templates for functions without implementations, requiring programmers to provide definitions.
  • Several participants discuss the purpose of interfaces, noting that they allow for separate implementation of functions and can enforce certain properties on classes.
  • One participant provides an example of the Runnable interface in Java, explaining its significance in multi-threaded programming.
  • Links to external resources, including amusing explanations and Wikipedia articles, are shared to provide additional context and information on OOP concepts.

Areas of Agreement / Disagreement

Participants generally agree on the definitions and roles of classes, objects, methods, and interfaces, but there is some contention regarding the necessity of labeled sample code versus understanding definitions. The discussion remains unresolved on the best approach to learning these concepts.

Contextual Notes

Some participants mention the importance of understanding the context in which interfaces are used, such as in multi-threading, but do not resolve the varying opinions on the necessity of sample code.

Passionate Eng
Messages
36
Reaction score
1
I have a problem with understanding the concepts of "object oriented programming"
I do not know what is an instance, object, method,interface...
I have read many examples from the real world
but I need a sample code with labeled instance, object, method, interface
I wish the idea is clear
 
Technology news on Phys.org
If you want sample code, you should tell what computer language you want it in.
 
sorry, i want java program
 
Passionate Eng said:
I have a problem with understanding the concepts of "object oriented programming"
I do not know what is an instance, object, method,interface...
You don't need sample code with these things labelled - what you need is to understand how these terms are defined.

You didn't ask about the term class, which is a user-defined type in Java, C++, C#, python, and other languages. A class definition is a template the the compiler or interpreter uses to set up memory when a variable of this new type is declared. The compiler doesn't actually allocate any memory for a class.

An object or instance (pretty much the same thing) is a variable whose type is whatever class the object is declared as. The compiler allocates memory for the data members of the class.

A method is object-oriented terminology for a function member for a class, as opposed to data members (sometimes called class properties).

An interface is a template for a set of functions that can be used by some class. The interface does not contain function definitions -- only declarations (or prototypes) of the functions, namely the names of the functions, the number and types of their arguments, and their return types. A programmer who wishes to use an interface has to write definitions (or implementations) for all of the functions listed in an interface.
Passionate Eng said:
I have read many examples from the real world
but I need a sample code with labeled instance, object, method, interface
I wish the idea is clear
 
  • Like
Likes   Reactions: fluidistic and Passionate Eng
Why do we use the interface?
 
Passionate Eng said:
Why do we use the interface?
You can write a program that uses the functions in the interface and someone else can write the implementation of the functions without more coordination. The development environment can easily check that you are using the functions with the correct interface and tell you when you have made a mistake. In the editor, you can put the function name in your code and it will give you a list of the valid calls available with that function name. It's a good thing.
 
Passionate Eng said:
Why do we use the interface?
I did a quick web search for "OOP interface" and here's one that was listed.
http://www.cs.utah.edu/~germain/PPS/Topics/interfaces.html
An interface is a programming structure/syntax that allows the computer to enforce certain properties on an object (class). For example, say we have a car class and a scooter class and a truck class. Each of these three classes should have a start_engine() action. How the "engine is started" for each vehicle is left to each particular class, but the fact that they must have a start_engine action is the domain of the interface.
 
An interface is a kind of software contract. If a given class implements an interface then it means that every instance of the class will have defined the methods listed in the interface which means you can refer to the object by its interface as along as you only need to call the methods of the interface.

A common example right from Java, is the the Runnable interface. If a class implements Runnable then it must provide the run() method. Programmers define classes using Runnable so the class can be used in a multiple threaded environment i.e. you can run instances of the class in different threads at the same time.

https://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html

Notice in the above Java tutorial that the programmer has two choices either to implement Runnable or to subclass from Thread. Implementing Runnable is far more flexible and considered a best practice over sub classing Thread. Subclassing from Thread means you can't subclass from any other class in Java so it limits your options in the long term.
 
  • #11
Wiki articles:

http://en.wikipedia.org/wiki/Class_(computer_programming)

http://en.wikipedia.org/wiki/Object_(computer_science)

http://en.wikipedia.org/wiki/Member_variable

http://en.wikipedia.org/wiki/Method_(computer_programming)

interface for oop:
http://en.wikipedia.org/wiki/Protocol_(object-oriented_programming)

interface for computing in general:
http://en.wikipedia.org/wiki/Interface_(computing)

http://en.wikipedia.org/wiki/Instance_(computer_science)

Instance - in the case of C++, template functions can be defined, including the code, using generic types for it's parameters, but don't generate any actual code. When C++ code includes a call to a template function with specific types, an "instance" of that function for those specific types is created within the code space of a program. Multiple calls to a template function with the same set of specific types will only generate one "instance" of a template function. In the case of Java, generic functions create code at define time, and parameters are handled as objects where the object type is handled at runtime.
 

Similar threads

  • · Replies 43 ·
2
Replies
43
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 32 ·
2
Replies
32
Views
7K
Replies
65
Views
5K
Replies
38
Views
4K
Replies
37
Views
6K
  • · Replies 25 ·
Replies
25
Views
6K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K