Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design Principles [closed]

Tags:

oop

principles

What principles do you generally follow when doing class design?

like image 647
therealhoff Avatar asked Sep 19 '08 01:09

therealhoff


People also ask

What is Open Closed Principle in agile?

The Open-Closed Principle (OCP) states that software entities (classes, modules, methods, etc.) should be open for extension, but closed for modification. In practice, this means creating software entities whose behavior can be changed without the need to edit and recompile the code itself.

Why do we need open and closed principles?

Open/closed principle is intended to mitigate risk when introducing new functionality. Since you don't modify existing code you can be assured that it wouldn't be broken. It reduces maintenance cost and increases product stability.

How do you use the Open Closed Principle?

The Open-Close principle (OCP) is the O in the well known SOLID acronym. A module will be said to be open if it is still available for extension. For example, it should be possible to add fields to the data structures it contains, or new elements to the set of functions it performs.

Which of the following is Open Closed Principle?

Definition of the Open/Closed Principle Bertrand Meyer wrote about it in 1988 in his book Object-Oriented Software Construction. He explained the Open/Closed Principle as: “Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.”


2 Answers

Principles Of Object Oriented Class Design (the "SOLID" principles)

  • SRP: The Single Responsibility Principle A class should have one, and only one, reason to change.
  • OCP: The Open Closed Principle You should be able to extend a classes behavior, without modifying it.
  • LSP: The Liskov Substitution Principle Derived classes must be substitutable for their base classes.
  • ISP: The Interface Segregation Principle Make fine grained interfaces that are client specific.
  • DIP: The Dependency Inversion Principle Depend on abstractions, not on concretions.

Source: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

Video (Uncle Bob): Clean Coding By Robert C. Martin ( Uncle Bob )

like image 160
Patrick McElhaney Avatar answered Sep 27 '22 21:09

Patrick McElhaney


Don't forget the Law of Demeter.

like image 21
Mark Avatar answered Sep 27 '22 22:09

Mark