1024programmer Asp.Net Getting Started with C#: How to Reasonably Formulate Method Parameters – Part 1

Getting Started with C#: How to Reasonably Formulate Method Parameters – Part 1

Getting Started with C#: How to Reasonably Formulate Method Parameters – Part 1

1. Use object-oriented principles to split the functions we face into related objects

2. The same function should only appear in one class.

3. Try to extract the common parts of similar functions

The overall goal is simply to reduce the amount of code.

Let’s use a dynamic condition query interface to illustrate the above points

This is a medical record query function. The list on the left is all the fields that can be selected, the middle is the field that the user requires to query, and the conditions for a certain query field on the right.

What classes are used to organize this interface function?

The result is not unique, everyone can have their own ideas. But I think organizing it in a way that more people can easily understand should be our goal.

The first thing that comes to our mind should be two objects: All fields and Field query range

Study the rules of all fields. More often, you should chat face to face with customers. We found that some fields use the same query range entry interface.
So there seems to be a field type hidden here. That is, the behavior of a certain type of fields is consistent, and the behaviors of interface entry, condition generation, etc. are consistent.

Field query range and field type are easy to think of as attributes of the field, rather than functional objects that construct the main elements.

Yes, the name is confusing. But if I change the name to “query scope” and “behavior controller”, you may understand my intention.

Three objects: field, query scope, behavior controller

The left display shows all the “fields”, and the noon display shows all the “query ranges”. The behavior controller must be an interface that allows the main program to handle all types of fields gracefully.

The picture above is the code for the intermediate query range selection event. This main program can handle the display of N types of fields.

This article is only published on the blog. Please do not reprint it without permission!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/811454

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索