17. Object oriented programming in Java

Posted by diggysmalls on Sun, 30 Jan 2022 20:03:57 +0100

Object oriented programming in Java

Author: Han Ru

Company: procedural coffee (Beijing) Technology Co., Ltd

Program coffee: IT vocational skill evaluation platform

website: https://www.chengxuka.com

task

1. object-oriented
2. Process oriented
3. Classes and objects

1, Object oriented design idea

Object oriented in life

Wash clothes and eat
 Process oriented: focus on the process -- think and do things from the perspective of an executor
	//step1. Find a basin
	//step2. Collect laundry
	//step3. Put water and washing powder..
	//Step 4: Wash
	//Step 5: bask in the sun

Object oriented: the focus is the object -- from the perspective of the commander
	//step1: find an object
	//Step 2: let him do the laundry
	
	
Object oriented in life: find the right person and do the right thing..
Facing the process in life: do it by yourself, follow the process steps step by step, and say it step by step...

In the code:
	Arrays class
		sort();-->sort
		binarySearch();-->search
	Scanner class
		sc.nextInt();
		sc.next();
		sc.nextDouble();

1.1 what is object-oriented

A way of thinking to look at problems, focusing on finding a specific individual with special functions, and then entrusting this individual to do something. We call this individual object
 It is an idea more in line with human thinking habits [lazy thought], which can simplify complex things and transform programmers from executors to commanders
 To use object-oriented development, first find the object with the required function. If the object does not exist, create an object with the required function

1.2 process oriented

A way of thinking about problems. When thinking about problems, focus on how to solve the problems step by step, and then solve the problems yourself

1.3 comparison between object-oriented and process oriented

Object oriented is based on the philosophical view that everything is an object

For example:

Case 1: I want to eat a large plate of chicken
Process oriented and object-oriented
​ 1. Go shopping by yourself 1 Entrust a person who can bargain to help buy vegetables
​ 2. Choose your own dishes 2 Entrust a temporary worker to help choose vegetables
​ 3. Cook by yourself 3 Entrust a cook to help cook
​ 4. Start eating by yourself 4 Start eating by yourself

Case 2: Xiao Ming is a computer Xiaobai. He wants to equip a computer. After buying the parts, he needs to transport them home. After assembly, he opens the computer and plays games
Process oriented and object-oriented
​ 1. Xiao Ming supplements computer knowledge 1 Entrust a friend who knows computer (Lao Wang) to help buy parts
​ 2. Xiao Ming goes to buy parts 2 A person who can buy parts can run errands
​ 3. Xiao Ming takes the parts home 3 Entrust an express brother to deliver Xiaoming to his home
​ 4. Xiao Ming assembles the computer 4 Entrust a person who can assemble computers to help Xiao Ming assemble computers
​ 5. Xiaoming starts up to play computer 5 Xiao Ming turns on his computer and starts playing games

object-oriented:(OOP)
	Not a language, but a programming idea.
	Object oriented programming:(Object Oriented Programming)
		Object: object
		Oriented: Orientation
		Programming: program
		
Process oriented:
	Focus on the process(step)
	step1,step2,step3.. . . . 
	Summation analysis can be realized according to the steps.

object-oriented:
	Focus on the object
		Everything is an object.
	A: Analyze the objects involved in the current problem domain.
	B: What features and functions do these objects have.
		External features: static attributes
		Action behavior: dynamic attributes
	C: Objects and relationships between objects.
		Inheritance relationship, aggregation relationship, association relationship...
		
		Stacking of classes.

Difference summary

a.Both are a way of thinking to look at problems and can solve problems
b.Process oriented, focus on all things and do it yourself
c.Object oriented focuses on finding an object with special functions and delegating this object to help do something
 Note: object orientation is an idea, not a programming language

2, Classes and objects

The idea of object-oriented programming tries to make the description of things in computer language consistent with the true face of things in the real world as much as possible.

Class and object are the core concepts of object-oriented method.

  • Class is the description of a class of things, which is an abstract and conceptual definition. people

  • An object is each individual of such things that actually exist, so it is also called an instance. Zhang San

2.1 definition of class

A collection [group] of entities with special functions. The class is Java The most basic unit of language

2.2 definition of object

In a class, an entity with special functions can help solve specific problems. Objects are also called instances

2.3 relationship between class and object

a.A class is an abstraction of an object,Object is the concrete embodiment of class
b.Java Things described in are embodied in the form of classes,Classes are abstractions of concrete things,The object is the real individual of such things

Classes and objects

classobject
Human PersonAcademician Zhong Nanshan, you, me, Wang Ergou, Li Xiaohua, Grandpa Yuan Longping, father Ma Yun..
Dogs Phantom, loyal dog Bagong, erha, Xiaotian
CatsDudu, Kaka, your cat, grandma's white cat
AutomobileMy black Great Wall car, 58 Red Flag cars, the car that hit me..
Notebook computerThe computer I use now is 15 inch pro, Wang Ergou's ASUS, and your daughter-in-law's Association
Mobile phonesMy Huawei Mate30, your Xiaomi mix2s and your daughter-in-law use Nokia n95
Class: actually refers to the category. A general term for the same kind of things. Describe such things,--->establish class
	Is an abstract concept.
Object:
	A specific instance of a class that exists objectively and can be used. Individual.

Topics: Java Programming OOP