[Knock on the door of C #] for Beginners: Concepts of classes and objects

Source: Internet
Author: User

Object-Oriented Programming: Concepts of classes and objects

[Description: This article is for beginners to just contact programming to see, the big guys may seem to feel very simple, don't blame]

Classes (Class)

Object-oriented thought comes from the cognition of the real world. The real world is so complex and diverse that it is difficult to know and understand. But smart people have learned to classify these intricate things, thus making the world a more orderly place. For example, we abstract the concept of automobiles from all kinds of automobiles, and the concept of cat is abstracted from all kinds of cats, and the concept of flowers is abstracted from colorful flowers. Cars, cats and flowers all represent a class of things. Each type of thing has a certain state, such as the car's brand, speed, horsepower, fuel consumption, seat number, kitten age, weight, hair color, flowers color, petal shape, petal number, are in the state of describing things. Each kind of thing also has certain behavior, for instance automobile starts, travels, accelerates, slows down, the brake, the parking, the cat catches the mouse, the flower blooms. These different states and behaviors distinguish the various kinds of things.

Object-oriented programming also uses the concept of class, to write things into a "class." In class, using data to express the state of things, using functions to achieve the behavior of things, so that the programming and people's way of thinking consistent, greatly reducing the difficulty of thinking.

Encapsulation (encapsulation)

Who is the most bull in the process of making a car? Of course not welded steel plate, nor the tire, not screw screws, but the design of the car engineer, because he knew the operation of the car principle. But when we drive, do we need to know how the car works? The answer is clearly not needed. The operating principle of the car has been encapsulated by a great engineer in the car, providing the driver with a simple interface that allows the driver to operate the car with a flexible steering wheel and various buttons.

Similar to manufacturing automobiles, object-oriented technology encapsulates the implementation details of the state and behavior of things in a class, creating a reusable "part". Once a class is designed, it can be used by tens of thousands of programmers who have no knowledge of its internal principles, like industrial parts. The designer of a class is the equivalent of a car engineer, and the user of a class is the driver. This allows programmers to take advantage of the "parts" that others have already written and focus on their own domain. "C # Beginner Class"

Interface (Interface)

Today you bought a plasma TV, you take out the remote control, manipulate the button, and begin to enjoy the wonderful TV program. People use the TV set through the remote control interface, and similarly, people use classes through the interface of the class. Programmers design the interface carefully for it while writing the class, while the well-designed interface is not only convenient for other programmers, but also facilitates the upgrade of the class.

If you're an environmentalist, you've recently replaced an incandescent light bulb with an energy-efficient fluorescent lamp. The incandescent lamp illuminates the whole room by heating the resistor wire, while the fluorescent lamp glows by activating the electrons of certain molecules in the air. Although they are different in principle, their function is the same--lighting. Because the two kinds of lamps have the same interface, so you just twist the incandescent lamp, and then twist the fluorescent lamp can easily realize the "parts" of the replacement. Similarly, in object-oriented programming, as long as the interface remains unchanged, you can arbitrarily change the implementation details of the class, with a better design class to replace the original class, to achieve the upgrade of the class.

Now the cost of software maintenance and modification has accounted for 80% of the whole software development, the class of this idea greatly facilitates the maintenance and modification of the program, reducing the cost of software.

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.