Answer the question
In order to leave comments, you need to log in
What are OOP violations?
I came across a rather old article from zeptolab with an analysis of their competition. There they were very scolded for "Gross errors in the code. They are most often associated with violations of OOP principles."
What can be understood by this?
Tried to google articles on the topic. But there are no "basic principles" and solidity on the first pages
Answer the question
In order to leave comments, you need to log in
Most likely encapsulation, inheritance and polymorphism mean. They are the most basic.
3 cherished words: inheritance, encapsulation, polymorphism. You can google a lot on them.
An elementary example of violating the encapsulation principle is declaring a class field public. It is necessary to make all fields private, and organize access to them through access methods like get..., set... or somehow more transparently, if the language allows (__get, __set in php, properties in C#). On inheritance and polymorphism, it is already more difficult to screw up, since the syntax most likely will not allow this. Although who knows what hidden possibilities a person has ...
Encapsulation violation. Outside (i.e. public) some data sticks out that can be changed, and the object goes into an inconsistent state.
abstraction inversion. Simple things that descendants are likely to need are not available even through protected.
Violation of the Liskov principle (broken abstraction). For the father, you made an assumption that is not true for the sons. The classic example is a rectangle and a square - it is assumed that the father can scale arbitrarily, which is not true for the son.
Class instead of interface. If possible, make the parent a dataless class with two kinds of functions: public virtual = 0, and protected/public non-virtual (the so-called utility interface). Inheriting from multiple data classes is very ugly (and impossible in many languages).
Almighty parent. Too much functionality came up with the parent class.
In general, show the interfaces (protected / public, no exact implementations) of your classes, and let's race what's wrong there.
Gang of Four, SOLID and other singleton-observer factories. Apparently the zeptolabs did not like how the authors mixed them in the code.
I sketched out all the snippets of phrases ...
In general, so far I have seen:
Did I understand you correctly, gentlemen? Is there anything else to add?
The main violation in someone else's code, which really bothered me when I was programming in OO languages, was ignoring the Liskov substitution principle.
That is, the code that works correctly with an object of the base class must also work correctly with the object of the derived class.
An example of a violation - the SSL socket in the Qt library is inherited from a simple socket, but requires other dances with a tambourine to correctly complete the connection.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question