Zookeeper
The so-called expert is the person who has made all the mistakes in a very small field.
--------- Question
The data center charging system has been in place for some time. Now, students are offline. When a student disconnects from the machine, the corresponding checkout service needs to be performed based on different user categories. As a result, he has come up with the design model he has learned. In this case, what models can be used? Summary. (Some models may be too stubborn, but it doesn't matter. The true meaning of learning lies in this. We will continue to repeat and experiment)
Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------
Preface
First, analyze the data that is needed for the next host.
Hourly fee for fixed users: the hourly fee for membership level
Hourly fee for temporary users: the hourly fee for temporary users
At least the computer time: if the student assumes that the computer time is earlier than this, the calculation is based on this time.
Preparation time: this time is not counted in the time when the student is on the computer.
Minimum Amount: if the host time is less than or equal to the host time, the calculation is based on this
Rule Mode
Similar blogs have been written in the Rule mode, such
Summary of Rule Modes
Class Diagram
Strategy interface: encapsulates algorithms for calculating the amount of users of different categories
Context class: encapsulates different roles. When an external call is performed, you do not need to know the algorithm. You can instantiate this class directly.
Code:
''' <Summary> ''' interface of the Policy ''' </Summary> ''' <remarks> </remarks> Public interface strategy''' <summary>'' ''' </Summary> ''' <Param name = "consumetime"> consumed time </param> ''' <Param name = "bill"> users of different types amount spent on the machine per hour </param> ''' <returns> returned consumption amount </returns> ''' <remarks> </remarks> function consumemoney (byval consumetime as single, bill as Single) as singleend interface ''' <summary> ''' fixed user implementation interface ''' </Summary> ''' <remarks> </remarks> public class regularuser implements strategy Public Function consumemoney (consumetime as single, bill as single) as single implements strategy. consumemoney 'if it is less than the preparation time, if consumetime <5 then return 0' is not charged if it is less than the minimum time on the machine, the minimum fee for elseif consumetime> 5 and consumetime <30 then return 2 else return Bill/60 * consumetime end if end function end classpublic class context 'abstract policy dim strategy as strategy = noder' constructor setting detailed policy 'note that using sub new () in VB.net () keyword to use the constructor sub new (byval _ strategy as strategy) me. strategy = _ strategy end sub 'The encapsulated policy method public sub count (byval consumetime as single, Bill as single) me. strategy. consumemoney (consumetime, Bill) end subend class
Note: This is only a demo of students' offline checkout.
To be continued ......
Thoughts on discontinuing students from the data room Charging System