Have you ever wondered what is oriented programming? Or how does object-oriented programming contrast with this? Other than perhaps expected, oriented programming is not a matter of its own, but merely complementary.
So, what is the correlation between object-oriented programming and oriented programming, What are the features of object-oriented programming in particular? And why is object-oriented programming still preferred today?
The most important aspect is the re-usability. This means that, there are responsibilities, for example, a class is exactly responsible for a functionality and encapsulates all the methods and variables that are required for it. Many of these implementations also have only one inheritance hierarchy, so they do not represent the capabilities of multiple inheritance.
Based on the principles of class nesting, many other constructs of modularity were still built. A typical architecture here is the encapsulation of business logic, data persistence, and user interface. In principle, this makes sense for the first time from the separation.
However, there are some operations that cannot be subordinate to these patterns. An example of this is the implementation of logging mechanisms. Logging is characterized by the fact that you actually write to the console or a file at any point in the code which is currently running.
Since this has to be done in many different places, this leads to very redundant code, which is poorly maintained, because if you want to change the logging mechanism in principle, you now have to go into the code at any point and change the logging mechanism.
A similar principle is in the case of security mechanisms. Which is as much as when other users want to access my application. In order to be able to guarantee complete security, I would now have to ensure, at every point in my code, i.e. in business logic, data persistence, and also in the user interface, that the respective user has just a correct authentication and also has the correct authorization.
The normal case is that you only have security on the user interface and once this security has been overcome, all other mechanisms for business logic and data persistence will not be grasped because they are simply not implemented. Based on the assumption that the user does not come past the user interface anyway.
This is now the task field that tries to solve AOP, i.e. oriented programming. The problems arising from the aforementioned examples are therefore the distribution of code, which is actually the same, but needs to be redefined in many places and the mixing, in which aspects such as security or logging in code, such as User interface or business logic where they don't really belong.
The solution that we are now aiming for with AOP is to be able to define central aspects. Aspects are therefore such things as logging security and many others that are automatically distributed to all other places where they are needed. Using the example of logging, you would now define in one place, whenever certain methods are called, you want to write to the log that these methods were called.
If necessary, the return value should also be written. This is exactly the statement you want to define centrally and have it automatically inserted in all places. Just to make it clear again.
Unlike many other programming paradigms, oriented programming is not a paradigm of its own, but merely an extension to traditional object-oriented programming. What is important at the site is that you do not have to change the existing parts of the code and the logic to get AOP. You can definitely use AOP to make certain changes by yourself.
The advantages that now arise from the use of oriented programming are much better modularization, because external functions such as security and logging can now be considered as separate modules. It also improves the customizability of this nesting, it is now possible to add or remove aspects at any time in the development cycle. This also makes it much easier, for example, to eliminate security during development in your own system.
Another interesting point is that, dependencies are now outside of their logic. For example, you could use certain frameworks to implement security mechanisms, and the dependencies on exactly these frameworks are no longer in the business logic, but only in the aspect. Especially for many principles of conventional development, there are cases for oriented programming.
For example, when one takes a close look at one of the core functionality of Spring framework. This is transaction management. With the help of AOP, it is now possible to ensure that all operations performed on a single transaction are performed within the same transaction. Therefore, it is no longer necessary to start a transaction on the database, but only the hint of a keyword that it is a transaction.
Another example is the implementation of security. By using one aspect, security is also given a global dimension. This means that in one place, the conventional safety is implemented worse than in another place, and the oriented programming is no longer possible.
Similar to the principles of logging, so-called audits or monitoring can be easily added to the existing code, using oriented programming. This also applies in particular, to cases, such as money transfer or similar transactions, because such operations would normally not be recorded by normal logging because they do not affect the application per se, but are still relevant as information.
Another possibility is to intercept events, that is, things that are triggered by the use of certain things. So if a user clicks on a particular button too often, you could log it out. Also this principle is similar, only redundant if it would be implemented on each button.
Sometimes, oriented programming is also useful for detecting errors in your own code. This way you can get across all instances and all methods as well as intercept and record variables. And probably the most classic aspect is logging, which can benefit most from object-oriented programming. Definitely, you can now reason with me on how oriented programming complements object-oriented programming and what benefits can be derived from it.
---------------------------------------- Written by a Techpally team member
Your buns are mine! But you can have this tiny ad: