What are the Concepts of Object-Oriented Programming?

  • Thread starter Passionate Eng
  • Start date
  • Tags
    Programming
In summary: In C++, the code is generated at compile time, and is tested at compile time. In summary, "Object-oriented programming is a programming paradigm that focuses on objects and their interactions. These objects are instances of a class, which is a user-defined type. Objects have data members and methods, which are used to manipulate the data. Interfaces are templates for functions that can be used by a class. They provide a way for the computer to enforce certain properties on objects and make programming more flexible and efficient. Sample code is not necessary to understand these concepts, but it can be helpful in learning how to apply them in real-world situations. In Java, interfaces are used to define a set of functions that must be implemented by a class. This allows for
  • #1
Passionate Eng
36
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
  • #2
If you want sample code, you should tell what computer language you want it in.
 
  • #3
sorry, i want java program
 
  • #4
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 fluidistic and Passionate Eng
  • #5
Why do we use the interface?
 
  • #6
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.
 
  • #7
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.
 
  • #8
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.
 

1. What is Object Oriented Programming?

Object Oriented Programming (OOP) is a programming paradigm that focuses on creating objects that have properties and behaviors. These objects can interact with each other to perform various tasks and form the basis of a program's structure. OOP languages include concepts such as classes, objects, encapsulation, inheritance, and polymorphism.

2. What are the main advantages of using Object Oriented Programming?

OOP offers several advantages, including code reusability, easier debugging and maintenance, and better organization of code. It also allows for faster development time and promotes a modular approach to programming, making it easier to scale and adapt the program as needed.

3. What is the difference between a class and an object?

A class is a blueprint or template that defines the properties and behaviors of an object. It serves as a model for creating multiple objects with similar characteristics. An object, on the other hand, is an instance of a class. It contains specific values for the properties defined in the class and can perform actions or methods defined in the class.

4. What is encapsulation in Object Oriented Programming?

Encapsulation is the process of hiding the internal workings of an object from the outside world. It allows for better control and protection of data by making it only accessible through methods defined in the class. This helps prevent accidental manipulation of data and promotes a more secure program.

5. What is the purpose of inheritance in Object Oriented Programming?

Inheritance is a mechanism in OOP that allows a class to inherit properties and methods from another class, known as the parent or base class. This promotes code reuse and helps maintain a hierarchical structure within the program. It also allows for easier implementation of new features or changes in the future.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
2
Replies
37
Views
2K
  • Programming and Computer Science
2
Replies
65
Views
2K
  • Programming and Computer Science
Replies
32
Views
5K
  • Programming and Computer Science
Replies
7
Views
463
  • Programming and Computer Science
Replies
25
Views
3K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
1
Views
740
  • Programming and Computer Science
Replies
1
Views
982
Back
Top