[JAVA] Summary of results of research on object orientation [Updated from time to time]

Summary of results of research on object orientation [Updated from time to time]

We will add and organize as needed.

What is object orientation?

There are things like the concept itself and no clear explanation.

** "Programming style that extracts frequently changed parts into classes, centering on the parts that do not change" **

In short, I understand that it is a way of thinking to program so that it is easy to change specifications and expand functions later.

What is inheritance is-a?

** The essence of inheritance is an interface that brings together abstract concepts **

--"Inheritance of functions" is not the essence --The difference between class inheritance and interface is that inheritance can inherit functionality from a superclass. --Composition is used more often than inheritance --EX.) New part 1, new part 2, new product (part 1, part 2)

What is polymorphism?

** Programming for an interface (abstract) **

--Do not program for concrete ("new" is concrete) ――It is not a problem that the number of dependent classes increases, but the problem is that it depends on the concreteness. --Instantiation without creating a factory should be done in the main class

What is encapsulation?

** Eliminate waste, refine and make something easy to understand **

--Layer is different from inheritance and polymorphism --Give the correct name to the class (maybe this is the worst ...) ――It doesn't work even if you put the real world into an object-oriented source.

How to name

For the time being, I will protect only the following.

--Camel case --Class is a noun or gerund --The method brings the verb first

5 Principles (SOLID Principles)

Single Responsibility Principle

** There must be no more than one reason to change the class (role = responsibility = reason to change) **

Open-Closed Principle

** ・ When there is a specification change, it is possible to deal with the change by adding behavior. -Adding behavior does not affect existing code **

Liskov Substitution Principle

What is desired is the following substitution property:

There is one T-type object o2 for each S-type object o1 There is a program p defined using o2 At this time, even if o1 is used instead of ** o2, the behavior of p does not change **

Interface Segregation Principle

** • Do not force the client to depend on methods that the client does not use **

-If you depend on a method that you are not using, it may affect clients that should not be related when that method is changed.

-Make each client depend on ** only the methods that it actually uses **

**-Group related interfaces and prepare a specialized interface for each client ** This allows the client to break dependencies on methods it doesn't use.

Dependency Inversion Principle

· Higher modules should not depend on lower modules, ** Both modules should depend on "abstract" **

· "Abstract" should not depend on implementation details, ** Implementation details should depend on "Abstract" **

-If the upper module follows the interface declared by the lower module, it can be said that the ownership of the interface belongs to the lower module.

** · Make relationships within the program end with an abstract class or interface, independent of the specific class ** No class derived from a concrete class Do not overwrite the methods implemented in the base class

Beware of over-abstraction

** ・ It is just as important not to do premature "abstraction" and to use "abstraction" **

There was an explanation. I would like to identify meaningful and effective abstractions.

Recommended Posts

Summary of results of research on object orientation [Updated from time to time]
[Eclipse] Summary of environment settings * Updated from time to time
[Updated from time to time] Ruby on Rails Convenient methods
Memorandum Poem (updated from time to time)
Language summary to learn from now on
I translated the grammar of R and Java [Updated from time to time]
[Reverse lookup] Spring Security (updated from time to time)
SpringBoot useful site collection (updated from time to time)
Summary of moss when updating from JMockit 1.4 to 1.30
[Updated from time to time] Links that are indebted
Touch all Spring "Guides" (updated from time to time)
Git commands that new engineers should look back on [updated from time to time]
Introduction to programming for college students (updated from time to time)
[Personal memo] Frequently used Java grammar updated from time to time
Personally recommended Intellij IDEA initial settings (updated from time to time)
The illusion of object orientation
Results of trying to use NVENC (CUDA) with Ubuntu 18.04 on WSL2
I tried to deepen my understanding of object orientation by n%
[Ruby on Rails] "|| =" ← Summary of how to use this assignment operator
How to convert param to hash with Rails controller (updated from time to time)
Upgrade from MYSQL5.7 to 8.0 on CentOS 6.7
From introduction to use of ActiveHash
Notes on migrating from CircleCI 1.0 to 2.0
From introduction to usage of byebug
[Swift] Summary of how to remove elements from an array (personal note)
[Java] Flow from introduction of STS to confirmation of dynamic page on localhost (1/3)
Summary of means when you want to communicate with HTTP on Android
Environment construction of Ruby on Rails from 0 [Cloud9] (From Ruby version change to Rails installation)