Ten Principles of object-oriented Software Development (II.)

Source: Internet
Author: User
Tags define inheritance object model domain client
Ten principles of Object Oriented Software development (turn two)



When you define the parameters of a method, be sure to make them extensible. For example, the following line of code is not extensible:

Public Function PlaceOrder (slastname As String, Sfirstname as String, saddress as String)

To invoke this method you must pass these 3 parameters. But if you later decide you need a phone number on an order, you must modify the function signature, which destroys compatibility and each code snippet that calls this method. To prevent this problem, a better solution is to pass parameters in a container. You can use a recordset, an array of variables, or an XML string to pass more general parameters.

When transferred to. NET, this technique is not very necessary, because in the. NET you can load a function so that you can have the same function with two sets of different parameters:

Public Function PlaceOrder (slastname _
As String, Sfirstname as String, saddress as String)
Public Function PlaceOrder (slastname _
As String, Sfirstname as String, _
Saddress As String, Sphone as String)

6. Use XML now

XML provides a good way to manage state and pass it between components of an application. You can define XML in any format you like, and then insert, UPDATE, delete, or review any information from an XML string.

The best thing about XML is its cross-platform nature and its own vendor. XML is neither Microsoft technology nor Sun technology, it is the World Wide Web Consortium that controls this standard, see the original in detail.

XML becomes the data access standard in. NET, so using it now will lead you all the way.

7. Define a flexible interface

Interface (interfaces) provides a good way to insert components at run time. You can define an interface, create a class that executes it, and then easily replace the class with any other class that performs the same interface at any time.

For example, you can develop a mailing list label print component, and define the standard interface required by this component. In this example, the interface includes the name and address information. Then, any class that executes the interface can use the component without any modification. A customer class that performs a label printing interface can use this component to print customer mailing labels, and a staff class that performs a label printing interface can use this component to print salary labels.

8. Inheritance function

Inheritance is a key principle of OOP, which allows you to define the underlying functionality of an object and then apply that functionality to specific subclasses of the object.

For example, you can define the underlying functionality for a customer object, recover and save data, and calculate a discount. You can then define a government client object that inherits all the functionality of the client object, but shields off the discount calculation because it gives government customers a higher discount.

In vb.net, you will soon be able to achieve these.

9. Processing according to the model

Developing a domain model that describes transactions is useful for understanding the purpose of an application and the problems it should address. But a common mistake is to get the domain model and try to encode it. Instead, you should fuse the domain model into an execution model that defines how to create a class. There are a number of factors to consider in the fusion process, see Building an object model.

10. Understanding OOP, using OOP

All of them. NET is Object oriented. The more you know about OOP now, the better you can understand it, and move on to it in the future. NET is easier. Be prepared to use the class model in all projects. If you don't understand OOP, or even though you know it but don't really understand it, you can use an OOP class. OOP technology will soon be your second self, and you'll find it difficult to remember how you coded it.



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.