C # Reasons for using objects

Source: Internet
Author: User

Four features of object-oriented (OOP:
Abstract: What classes should my project have? By observing database design, we can help us find classes.
Encapsulation: Do your own things and do not expose your internal things too much.
Inheritance: the compatibility between classes. The relationships between things are not just level relationships, but also abstract and specific relationships (general and clear relationships). They are compatible.
Polymorphism: A method corresponds to multiple implementation methods (multiple forms). When calling a method, It should be intelligently and accurately called.

Why use a class: it is a skill to compress regular things into a template and simplify development. It can organize code according to human logic.
Why do we use static: because in a thing (a class), some are common features (such as the total number of humans), some are different from person to person (person's height ), we mark the common features and behaviors as static, which can be used without the need for new (instead of relying on new to create an individual ).
Why use constructors: to avoid missing Raw Materials
Why do we need to use function overloading: Leave convenience to customers, and do not provide too many service windows for similar businesses?
Why use attribute (get set): It is a method of Deformation: it is used as a field, actually a method. The function of this method mainly provides internal data filtering (like the check constraints of a database)
Why using the indexer: it is also a method of deformation and has the opportunity to use the [] syntax for everyone

 

Why is constant used (const) organized because fixed agreed values are uniformly managed in the project?
Why is it better to use enumeration (enum) because it expresses several States and is optional?
Why should I use the structure (struct)? Because after learning the stack graph, I know that struct does not need to follow the clues. It is very efficient in size, but I should use it with caution, because of the ease of binning and unpacking, the embedded classes are still messy and inefficient when the volume is large.
Why do we need to know how to unpack a box: Because the packing is automatic, we hope you will avoid unpacking as much as possible, instead of letting everyone learn how to install and unpack a box.

Why set (List, ArrayList): Because the array length is difficult to manage, we need to dynamically increase the array length.
Why is the preferred generic set (List <>): Because ArrayList is a waste bin, and the services provided by the value type are not in place (binning is required)
Why select a dictionary: because the List set is slow in searching, you need to consider the dictionary set when there are frequent searches. However, note that keys and Values sets need to be bound and converted.
Why use XML for data transmission: Because the xml format can clearly express the sense of attention in text files, it is very dangerous to directly connect to the database to obtain data through the public network, and the server will find the data, use a clear xml expression to pass the file to the other party for parsing.
Why use Xml to configure data: Because text files are too simple to express, once many items need to be configured, they will be messy, so xml can be clearly expressed.
Why use IO stream to access data: because not all databases need to be used, such as simple information storage
Why do we need serialization: Just like reinstalling a computer, it is better to connect a belt and shell like ghost than to install a common software one by one. Don't forget that the common method is to remove and install a lot of work.
Why use serialization to transmit data: simple, efficient, overall storage, and overall restoration
Sometimes, we need to transmit data in XML instead of serialization: In serialization technology, both parties must agree to use a common class to store and restore data, this results in special requirements for deployment and can only be used on the same platform. xml is inefficient, but it does not have these disadvantages.

Why use reflection: reflection is a host machine that not only can see the structure of the assembly and class, but also can clone the object through gene type, so that we can use a set of programs and classes (by path strings and class name strings), without importing them in advance in the project, play an irreplaceable role

Why should we use inheritance? Inheritance describes the compatibility between classes. Using inheritance can help us break down complicated problems: once our problems are complex, the solution is classification, which breaks down the problem one by one. inheritance is a general problem, which is categorized into specific problems (Child classes). If the problem is complicated, it is further refined. This decomposition is the use of inheritance.
Why do we need polymorphism: we find that inheritance only solves the compatibility relationship, and compatibility causes multiple classes to be mixed in the same set, but when you issue a command, it does not mean that every class object knows to call its own method. (If you cannot accurately call methods that vary from person to person, then compatibility is meaningless.) So we use the polymorphism syntax to solve the problem of automatic calling.

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.