Object-oriented programming is a paradigm, a view of how to program. You'll soon see for yourself that OOP brings a pretty fundamental simplification to all the common problems and difficulties that are solved over and over again in real programming.
The basic idea of object-oriented programming is to divide a large application (a complex task) into many small parts that we can solve elegantly and independently.
For example, if we are programming a reservation system for airline tickets, it is a very complex project that solves thousands of cases. If we can decompose the whole complex logic into many layers and parts, we can easily understand the whole complex system and program the individual subtasks independently.
Apart from the academic viewpoint, there are many practical reasons to use OOP:
Personally, I can't imagine teams with more than one person programming any differently.
Note:
Using objects puts a little more memory and CPU overhead on the computer, so this will reduce application performance a little. In a real-world environment, however, this doesn't matter, because reprogramming the application to objects does lose some performance (usually units of percent), but it saves programmers time (usually tens to hundreds of percent). Human time is always much more expensive (and very limited) than computer time.
Don't forget also that OOP brings great simplification to the whole application and allows large applications to be completed in a reasonable amount of time. A large number of complex applications would be almost impossible to program without objects.
The basic goal of OOP in software design is to simulate as much as possible the properties, behaviors, and principles of the real world. Objects in OOP represent real entities. This way of thinking allows us to build huge complex systems that can be well understood, solve real-world problems internally as they would be solved without a computer, and the principles can be explained to real people.
For example, if we are implementing a content management application, it makes sense to lay out all the internal logic in many real entities (article, author, category) and to build sessions not according to artificially generated record IDs (as is conventionally done in databases) but according to real relationships.
Example of concrete implementation:
class Article{private Author $author;/** @var Category[] */private array $categories;private string $title;}class Author{private string $name;}class Category{private string $name;}
As we can see, the Article
class does not only contain technical parameters, such as the ID of the record with the author, but it is a real binding to the Author entity, which again has its own properties.
For an explanation of the specific implementation and syntax, see the introductory tutorial.
Jan Barášek Více o autorovi
Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.
Rád vám pomůžu:
Články píše Jan Barášek © 2009-2024 | Kontakt | Mapa webu
Status | Aktualizováno: ... | en