An article takes you to understand Java OOP ideas

Deep analysis of Java OOP thought

Java Object Oriented Programming

Object-oriented programming referred to as OOP (Object-object, Oriendted-oriented, Programming-programming)

Object-oriented in general, refers to the use of rich object content for programming

Introduction of OOP

In a project, if the same method exists in different classes, this will reduce the coding efficiency of the program and the code redundancy and reusability will deteriorate. Therefore, a method is proposed, which is to use a class to encapsulate the same method in different classes, and then when using this method, create an instance to code, so that the coding efficiency of the program will be improved, and it will not appear. Code redundancy.

POP and OOP

Process-oriented

Design ideas: from top to bottom, hierarchical and decomposed

Design method: program = algorithm + data structure

Features: independent of each other, redundant code, inconsistent data and program, difficult to maintain

Example: buy a computer (you can play and eat chicken)-go online or consult relevant people to understand the required configuration-list the configuration list according to the configuration you need-take the configuration list to the computer city to find a computer vendor-consult the price and pay Money-wait for the computer to be assembled-take home

Object-oriented

Design ideas: bottom-up, object-oriented, comprehensive

Design method: program = object = data + method

Features: Simulate the objective world, similar to the way of human thinking, capable of code, consistent with data and procedures

Example: buy a computer (you can play and eat chicken)-find the relevant person who understands the computer-inform the demand and consult the price-pay the money-wait for the computer to go home

Relationship between the two

Object-oriented is based on process-oriented

Object

The object is the core part of OOP, is a concrete entity that actually exists, with a clearly defined state and behavior.

The object is the encapsulation of "data" and "method", where: data represents its own state, also called attributes; method represents its own functions, also called functions.

It can be said that everything is an object in Java programming.

Class

A class is called a class. In real life, things in our lives are often divided into classes. Things in the same class have the same characteristics and define entities with the same characteristics and behaviors; in Java, classes have the same attributes A collection of objects for sum and behavior.

The relationship between class and object

Class is to describe things; objects are instances of things described (use instance names to access members in the class)

First there is the description of the class (class), and then the object describing the class (class name instance name=new class name();)

Attributes

The characteristics of things in life are represented by variables in classes. Each attribute of each object has its specific value. The characteristics of objects or entities are called attributes in the class.

method

The behavior or action of a thing is represented by a method in a class. Each object has its function and behavior, and each function or behavior of an object is a method.

Three OOP Features

Package

Pack something together and present it in a complete form

The process of hiding (private) attributes, methods or implementation details is called encapsulation

Encapsulation is essentially to selectively hide some important information, which largely guarantees the security of the data.

inherit

Keyword: extends

Inheritance is a feature of reusing existing classes to generate new classes

Simply put, it is to make the new class have some characteristics of the existing class, for example, in reality, children will have some characteristics of their parents

In Java, inheritance can achieve code reuse.

Polymorphism

Polymorphism means that the same method has different implementations in different classes.

abstract

Keyword: abstract

When the function in a transaction has no concrete method body, or when things cannot be described clearly, it is called abstract;

Abstract classes cannot be instantiated (objects cannot be created);

The subclass inherits the abstract class and must rewrite all the abstract methods in the abstract class before the subclass can create objects;

The method modified by abstract must be included in the abstract class. (In the abstract class, ordinary methods can be written).

interface

Keywords: interface

If things encounter extended functions, use interfaces to solve them, implement interface keywords: implements;

Only constants and abstract methods can be defined in the interface (with fixed modifier format);

The interface cannot be instantiated;

Subclasses that implement the interface must rewrite all the abstract methods in the interface before creating the sub-object;

The interface is to expand the function of things, but the core idea of ​​the interface is to solve the problem of multiple inheritance, and use the way of multiple implementation of the interface to replace multiple inheritance.

API

Refers to some pre-defined methods, or an agreement to connect different components of a software system. It is used to provide a set of routines that applications and developers can access based on certain software or hardware without having to access the source code or understand the details of the internal working mechanism.


Guess you like

Origin blog.csdn.net/ITMuscle/article/details/109173338