Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classes. What's the point?

Tags:

I'm fairly new to OOP in PHP, I've made a couple of basic scripts but nothing impressive. All I've really taken from it is that it would probably be easier just make a collection of functions and include them.

The structure of classes seems to just confuse what was otherwise a simple process. And in collating everything into a class it doesn't really add any functionality.

So I'm clearly missing something. Could someone explain what functionality is added by creating classes

like image 608
Ben Shelock Avatar asked Jan 03 '10 01:01

Ben Shelock


People also ask

What is the point of class in programming?

In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).

What is the point of classes in Java?

What the purpose of creating a class? Short answer is, classes help you take all the properties and behaviors of an object in your program, and combine them into a single template. Yes, a class in Java is simply a template for creating objects with similar attributes and behavior.

What is the point of class inheritance?

Inheritance enables you to create new classes that reuse, extend, and modify the behavior defined in other classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class.


1 Answers

Classes are a notion of object-oriented design (and programming and analysis, respectively), where they are used to encapsulate data and methods.

Other object-oriented programming techniques may include features such as

  • information hiding,
  • data abstraction,
  • encapsulation,
  • modularity,
  • polymorphism and
  • inheritance

From an article .. top-15-best-practices-for-writing-super-readable-code:

Object oriented programming can help you create well structured code. But that does not mean you need to abandon procedural programming completely. Actually creating a mix of both styles can be good.

From http://java.sun.com/docs/books/tutorial/java/concepts/class.html:

In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created.

Finally, a short youtube video about the differences between the procedural and object-oriented programming paradigm ...

like image 114
miku Avatar answered Nov 16 '22 22:11

miku