(1) category design:
1. Operator Enumeration
Enum caltypewithtwounit
Add sub multi Div 5512915179
Enum caltypewithoneunit
Twice (square) SQRT (open) daoshu (reciprocal) OPP (reverse)
2. Subclass
Inherited from the parent class calactionbase
In this parent class, all sub-operators must perform operations.
Validate verifies the validity of the operand
The operation type is converted and then calculated.
The calculate abstract method is implemented in each subclass.
3. Interface icalculator
Method: pushnum pushcal backaword (undefined) reset (reset)
Clearoneoppend (clear current operand)
Attribute: The result read-only format has only one get Method for external calls.
4. Interface implementation class Calculator
Inherited interface icalculator
For specific calculation, there must be a calactionbase reference _ Action
_ Action: The calculate method can be called, while the calactionbase method is an abstract method.
Therefore, when _ Action instantiates objects of different subclasses, you can call the implementation body of the calculate abstract method in the subclass-Polymorphism @@@@@@
(2) Business logic:
1. Call in form1:
Define an interface _ ical = new calculator (); then, _ ical can call all methods and attributes of the interface
2. Analyze the functions of the above classes again, and it is not difficult to find out
Each operation subclass is only an operation for specific calculation behaviors.
Calactionbase, as the base class, is only an overall arrangement of each suboperation and can only contain public operations in some specific operations.
There is naturally no implementation of the method body in the interface.
The calculation logic of the subject will naturally be in calculator.
3. Analyze the attributes and fields in Calculator
(1) Reference _ action of a calactionbase class. This must exist, and the reason will not be repeated.
(2) string _ strexp of an overall arithmetic expression
Set a get Method for external calls to display all input
Also used for the clear operation (c)
(3) an operand string _ strnum
Used for clearoneoppend operations (CE) and backaword operations
Set a get Method for external calls to display the current input.