We seem to always have a bit more annoying to choose this word. When we choose to live, give up passion.
When we choose programmers to give up time. All this is dynamic to choose. And
Non-fate decisions. But in dynamics, I will decide. Well, now consider a relatively realistic
Question. Suppose. If you have a temporary meeting. But you can't determine when you are going. Because it is temporary
Determine. If you can't decide. If you have time it is 5: 00 - 6: 00, then you have to participate. Otherwise
You can still stay in the company office. And the meeting and office need to organize the file, then this is unable to
Determine factors. Maybe it can be judged with IF. So it is a very complex situation.
And considering that multiple component objects are obvious to coordinate, it is obvious that simple IF is difficult to bear such responsibility.
So you must use object-oriented mode. Since decision-making is determined in dynamics. So you can't get one
It is more exactly the way. So consider the abstract class. And the late binding is very realistic. So
Let's consider the relationship between responsibilities and responsible people. Responsibility is to choose from the solution and decision makers itself.
The solution is made up of many. It is obviously not possible to decide in advance. It must be done by an abstract object.
It is determined by its derived object. The decision makers are responsible for the decision to choose. It is also dynamic
Select the policy. So after analysis, the rule is simulated
// Specify policy public abstract class meetings, {//, no matter what solution must be sorted out of the collection public void planfile () {Console.WriteLine ("finishing file");} public abstract void selectcase ();
Public class onmeeting: meetingcase {
Override public void selectcase () {planfile (); console.writeline ("go to meet");}}
Public class Nomeeting: Meetingcase {
Override public void selectcase () {planfile (); console.writeLine ("stay in company office");}}
// Strategy decision
Public interface islectcase {meetingscase mc {get;}; void executecase (); void change
public class MeetingSelect {private MeetingCase Mc = null; public MeetingCase mc {get {return Mc;}} public void ExecuteCase () {Mc.selectCase ();} public void ChangeCase (MeetingCase NewCase) {this.Mc = NewCase;}}
Public class client {public static int main (String [] args) {ietenguctcase ms = new meetSelect (); meetingscase = new onmeeting (); meetingcase nm = new Nomeeting ();
IF (DateTime.Now.Hour == 5) {ms.changecase (om); ms.executecase ();} else {ms.changecase (nm); ms.executecase ();} return 0;}}} You can keep decision rights in advanced decisions.