Dark Horse Programmer----Java Basics----An overview of object-oriented thinking and classes

Source: Internet
Author: User

------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------

Object-oriented (mastering)

(1) Object-oriented
Object-oriented is a process-oriented programming idea.
Object-oriented and process-oriented differences: process-oriented emphasis is on the specific steps of each function. Object-oriented emphasizes the object, which is then called by the object to invoke the function.
(2) Object-oriented thought characteristics
A: It's a thought that's more in line with our thinking habits.
B: Simplifying Complex things
C: Let's turn from the executor to the conductor

Example:
Buy a computer
Process-oriented: Know your computer---understand your needs---compare computer parameters---Go to zhongguancun to buy a computer-buy back the computer.
Object-oriented: Want to buy computer---Find people who understand the computer to buy---others help me to buy back.
Wash Clothes: Process-oriented self-wash, object-oriented washing machine wash.
Cooking: Process-oriented self-made, object-oriented rice cooker do.
...
Everything is object.
(3) Load the elephant into the refrigerator (understanding)
A: Process-oriented implementation
B: Object-oriented implementation

Note: How do we make our operations more consistent with object-oriented thinking?
A: What are the classes
B: What are the members of each class
C: Class-To-class relationships
(4) Classes and objects
A: Things in the real world
Property The basic description of things
Behavior The function of a thing
The most basic unit in the B:java language is the class. So, we're going to use classes to show things.
C: Class
Member variables Things Properties
Member Methods Behavior of Things
D: Class: Is a set of related properties and behaviors. is an abstract concept.
Object: is the concrete existence of this kind of thing, is a concrete instance. Object

Example:
Student: Class
Monitor: Object
(5) Definition and use of class
A: Definition of class
Member variables The definition format is the same as before, where the location is different, in the class, outside the method.
Member Methods The definition format is the same as before, which is to remove the static.
Note: Defining a class is actually defining the members of the class (member variables, member methods)
B: Use the contents of the class
A: Create an object? Format
Class Name Object name = new class name ();
B: How do I use member variables and member methods?
Object name. Member Variable
The name of the object. Member method ()
(6) Case:
A: Definition and use of student class
B: Definition and use of mobile phone class
(7) Memory diagram
A: Memory diagram of an object
B: Memory diagram of two objects
C: Memory diagram of three objects
(8) Development, design, and characteristics of Java programs
A: Development: Is the constant creation of objects, through the object call function
B: Design: To manage and maintain relationships between objects
C: Features
A: Package
B: Inheritance
C: polymorphic




Add
One: An overview of object-oriented thinking
1: Object Oriented thinking
Object-oriented is a process-oriented programming idea.

Process oriented: Emphasis on the steps of each of these functions
Object-oriented: emphasizes the object and then invokes the function by the object

2: Object-oriented thinking features
A: It's a thought that's more in line with our thinking habits.
B: Complex things can be simplified
C: Turning us from the executor to the conductor

Example:
Buy a computer:
Process-oriented: My understanding of the computer--understand my own needs--find the corresponding parameter information--go to Zhongguancun to buy a computer--bargain--Buy back the computer
Object-oriented: I know I want to buy a computer--the squad leader buys it for me--the monitor buys it back.
Wash Clothes:
Process: Take off your clothes--find a basin--put some washing powder--add some water--throw your clothes in--rub--wash your clothes--wring dry--hang up
Object-oriented: Take off your clothes--open the fully automatic washing machine--throw it in--one click--Hang Up
Eat:
Process oriented: Go to the supermarket to buy food---------------------------------
Object-oriented: Dinner at the restaurant, you-waiter (à la carte)-Chef (cooking)-Waiter (end dish)--eat

Home-cooked things, buy a washing machine and go to a restaurant is too bad, so, find an object.
However, you do not study hard with me, you will be 4000, you object 8000.

3: Put the elephant in the refrigerator
Process oriented:
What are the actions?
A: Open the refrigerator door
B: Loaded into the elephant
C: Close the refrigerator door

Code embodiment;
Class Demo {
public static void Main (string[] args) {
/*
System.out.println ("Open the refrigerator Door");
Open the door of the refrigerator thing, I now just to demonstrate, wrote an output statement
In fact, it may take a lot of action.
This time, the code is a little bit more.
Suppose I had to open the refrigerator door many times,
Code a lot, write it again every time, trouble not
We should use methods to improve

SYSTEM.OUT.PRINTLN ("Loaded into the elephant");
System.out.println ("Close the refrigerator door");
*/

After writing the method, the call changes the
Open ();
In ();
Close ();
}

public static void Open () {
System.out.println ("Open the refrigerator Door");
}

public static void in () {
SYSTEM.OUT.PRINTLN ("Loaded into the elephant");
}

public static void Close () {
System.out.println ("Close the refrigerator door");
}
}

Object-oriented:
How can we be more consistent with object-oriented thinking?
A: What are the classes?
B: What are the things in each class?
C: What is the direct relationship between classes and classes?

The analysis of the elephant in the refrigerator? (How do you analyze which classes are available?) Uml. Noun extraction method. )
A: What are the classes?
Elephant
Refrigerator
Demo
B: What are the things in each class?
Elephant:
Get in
Refrigerator:
Open the door
Close the door
Demo:
Main method
C: What is the direct relationship between classes and classes?
The function of the elephant and refrigerator class is used in the demo.

The code reflects:
Class Elephant {
public static void in () {
SYSTEM.OUT.PRINTLN ("Loaded into the elephant");
}
}

Class Refrigerator {
public static void Open () {
System.out.println ("Open the refrigerator Door");
}

public static void Close () {
System.out.println ("Close the refrigerator door");
}
}

Class Demo {
public static void Main (string[] args) {
Refrigerator Call Open
Elephant calls in
Refrigerator call Closed
}
}

4: Development, design, characteristics
Object Oriented development
is to constantly create objects, use objects, and command objects to do things.

Object-oriented design
is to manage and maintain the relationship between objects.


Object-oriented features
Package (encapsulation)
Inheritance (inheritance)
Polymorphic (polymorphism)


II: An overview of Classes and objects
How do you describe a thing in the real world?
Example: Student
Name, age, gender ...
Study, Eat, sleep

Properties: Descriptive information about the thing
Behavior: What the thing can do

We learn programming languages in order to simulate things in the real world.
and the most basic unit of the programming language we learn in Java is: class.
So, we should put things through the class to reflect:
In this way, we get the correspondence between the real world things and the classes:


Things: Class:
Property Member variables
Behavior Member Methods


Class: is a set of related properties and behaviors. is an abstract concept.
Object: Is the concrete manifestation of this kind of thing. Specific existence of the individual.


Example:
Student: Class
Monitor: The monitor is an object

Dark Horse Programmer----Java Basics----An overview of object-oriented thinking and classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.