[Learning notes] [OC language] Object-oriented Thinking, learning notes oc

Source: Internet
Author: User

[Learning notes] [OC language] Object-oriented Thinking, learning notes oc

I. object-oriented and process-oriented ideas
OC is object-oriented and C is process-oriented. Object-oriented and process-oriented are only two different ideas for solving problems.
1. Differences between object-oriented and process-oriented
1. Take listening to songs on a computer as an Example
Process-oriented
Turn on your computer
Play songs on your computer
Turn off your computer

2 object-oriented (not an "object" of a blind date ")
Computer
Start
Play songs
Shutdown

2. Difference Analysis
Process-oriented focuses on the steps required to solve the problem, and object-oriented focuses on the objects required to solve the problem.
Without development experience, it is difficult to feel the difference between them. Both ideas can achieve the goal of solving the problem, but they have different solutions.

Object-oriented examples in real life
If you want to call or send a text message to your mobile phone, you do not need to analyze how the phone can be called.
Go to a restaurant to find a waiter. You don't have to analyze how to cook in the kitchen.
If the car breaks down, contact the Car Repair Engineer.
Realm: all objects

3. Common Terms
Process-Oriented Procedure Oriented
Object-oriented Object Oriented (OO for short)
Object-Oriented Programming Object Oriented Programming (OOP)

Ii. Relationship between classes and objects
Object-oriented has two very important concepts: class and Object
1. How to create an object
Real-life example: how to create car objects?
The vehicle construction drawings must be in place to clearly describe the attributes and functions (Actions) of the vehicle)
Attribute: Number of wheels, speed
Function (behavior): Run
Then generate a car based on the description on the drawing.
Every car is an object and has its own specific property value. It is an example of a drawing.
The drawings are abstract and the house is specific. Drawing is a high-level generalization of House objects

2. Surface object in OC
Classes in OC are equivalent to drawings used to describe a class of things. That is to say, to create an object, you must first have a class
OC uses classes to create objects. Objects exist in classes.
Therefore, to solve the problem, we should first consider which classes need to be designed and how many objects need to be created using the classes.

3. What classes should be designed and how to design classes?
1. Class Design:
1> Class Name
* The first letter of the class name must be in uppercase.
* Underlines are not allowed.
* Multiple English words, identified by camper
2> attributes
3> behavior (function)

2. Plants vs. botnets
* Class Name: Zoombie
* Attributes: life, speed, gongjili
* Behavior: walk, bite, and die

3. Lightning planes
* Class Name: Plane
* Attributes: life, gongjili, speed, and bombCount
* Behavior: fly, bomb, shoot, and die

4. Computer
* Class Name: Computer
* Attributes: band and expireDate
* Action: open and close


General nouns are all Class
The tank fired three shells and fired two planes.
James leads a dog with a hot dog in the bus.

Objects with the same (or similar) attributes and behaviors can draw a class.
Which object knows the behavior the most, and writes the behavior to which object. Turn on the computer (BOOT) This behavior should belong to the computer.

 

Related Article

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.