TechAid24

Your Technical Consultant

Ultimate Object Oriented Rules Cheat Sheet – Master OOP Instantly

Posted on by Anonymous Guest 3 minutes read

Let’s start with Ultimate Object Oriented Rules Cheat Sheet for Instant Success.

SOLID
Single Respon­­si­b­ility PrincipleA class changes for only one reason
Op­en/­­Closed PrincipleA class should be open for extension, closed for editing
Li­skov’s Substi­­tution PrincipleDerived types should cleanly and easily replace base types
In­terface Segreg­­ation PrincipleFavor multiple single­­-p­u­rpose interfaces over composite
De­pen­­dency Inversion PrincipleConcrete classes depend on abstra­­ct­ions, not vice-versa

SOLID principles

Common Refact­­orings
Encaps­­ulate Field
Generalize Type
Type-C­­he­cking ⇒ State/­­St­r­ategy
Condit­­ional ⇒ Polymo­­rphism
Extract Method
Extract Class
Move/R­­ename Method or Field
Move to Superc­­la­s­s­/S­­ubclass

More Refact­­orings

Basic OO Terms
Abstra­­ctionThe process of separating ideas from specific instances of those ideas at work.
Polymo­­rphismThe provision of a single interface to entities of different types. Subtyping.
Inheri­­tanceWhen an object or class is based on another object or class, using the same implem­­en­t­a­tion; it is a mechanism for code reuse. The relati­­on­ships of objects or classes through inheri­­tance give rise to a hierarchy.
Encaps­­ul­ationEnclosing objects in a common interface in a way that makes them interc­­ha­n­g­eable, and guards their states from invalid changes.
Other Principles
DRY – Don’t repeat yourselfDuplic­­ation should be abstracted
Hollywood Principle“­­Don’t call us, we’ll call you”
YAGNI – You Ain’t Gonna Need ItOnly code what you need now
KISS – Keep it simple, stupid!Favor clarity over cleverness
Law of DemeterOnly talk to related classes
Convention Over Config­­ur­ationDefaults cover 90% of uses
Encaps­­ul­ationWhat happens in Vegas…
Design By ContractAnd then write tests
Low CouplingMinimize the depend­encies
Common Closure PrincipleClasses that change together, stay together
Avoid Premature Optimi­zationDon’t even think about optimi­zation unless your code is working
Separation of ConcernsDifferent functi­ona­lities are distinctly managed
Embrace ChangeExpect and welcome any changes
Basic Principles
Encaps­­ulate what varies
Code to an interface rather than to an implem­­en­t­ation
Each class in your applic­­ation should have only one reason to change
Classes are about behavior and functi­­on­a­lity
Design Patterns
Abstract FactoryCreational
BuilderCreational
Factory MethodCreational
PrototypeCreational
SingletonCreational
AdapterStructural
BridgeStructural
CompositeStructural
DecoratorStructural
FacadeStructural
FlyweightStructural
ProxyStructural
Chain of Respon­­si­b­ilityBehavioral
CommandBehavioral
Interp­­reterBehavioral
IteratorBehavioral
MediatorBehavioral
MementoBehavioral
ObserverBehavioral
StateBehavioral
StrategyBehavioral
Template MethodBehavioral
VisitorBehavioral
Favor the following over inheri­­tance
DelegationWhen you hand over the respon­­si­b­ility for a particular task to another class or method.
Compos­­itionUse behavior from a family of other classes, and change that behavior at runtime.
Aggreg­­ationWhen one class is used as part of another class, but still exists outside of that other class.
Access Modifiers
PrivateOnly inside the same class instance
ProtectedInside same or derived class instances
PublicAll other classes linkin­­g/­r­e­fe­­rencing the class
InternalOnly other classes in the same assembly
Protected InternalAll classes in same assembly, or derived classes in other assembly
StaticAccessible on the class itself (can combine with other accessors)

Tags:

Anonymous Guest

An anonymous author is a writer who conceals their true identity when publishing content, often for privacy, security, or confidentiality reasons. This approach is often used in technical articles to focus on the information being presented rather than the author's personal identity.

Leave a Reply

Your email address will not be published. Required fields are marked *