What is the difference between the open / closed principle and the dependency inversion principle?

I read articles about SOLID but I see no difference between OCP and DIP. Take a look at this OCP example:

http://www.oodesign.com/open-close-principle.html

Code that contains OCP also performs DIP. Can someone give me an example of code that contains OCP, not DIP?

+5
source share
1 answer

I find dependency injection explanations and open / closed to confuse. That should not be so. Let's take a look at the article you are referencing: http://www.oodesign.com/open-close-principle.html

GraphicsEditor . , , GraphicsEditor : drawShape; DrawCircle; DrawRectangle.

, Parallelogram? Parallelogram , GraphicsEditor, drawParallelogram.

"", : , . Shape (Parallelogram) GraphicsEditor (drawParallelogram).

, . , 20 . -, , , , : . , , , . -, , , GraphicsEditor. . . , .:-) ( .)

, , GraphicsEditor. , .

. . GraphicsEditor , "Shape" "draw". GraphicsEditor , . GraphicsEditor. GraphicsEditor "". , " " - . .

- . , : http://sourcemaking.com/design_patterns/visitor. , .

+4

All Articles