The Template Method of Design Patterns

It's been annoying recently. As the home of programmers, the blog garden is not fake. Although the essays I have written now are rarely read. Just entertain yourself. Troubles are caused by contradictions, and many people's thoughts are affected by the external environment. For example, a decision that has been thought for for a long time, when something really happens, it is over-considered, and it is changed by the influence of the external environment.

The interview really depends on skills. Although you are very NB, the interviewer does not know, and it is no use if they do not give you a chance. Not many people really know your NB, because people are easily deceived by illusions.

If you want to have a relationship with me, you should be responsible for me. In the object-oriented relationship, there are inheritance, implementation, association, composition, etc.

The first time is a routine, because a routine is a stepping stone.

The members of the object belong to the implementation of the interface, the rewrite of the abstract class, the rewrite of the virtual method, and the intentional rewrite of new.

Inheritance is about what you already have.

People's vision is very important. For example, a 60-year-old who has been in the countryside and has never seen the world has a hard time understanding our generation. The biggest trouble of my beloved old father is that I am not married. His thoughts are not only thinking about this matter, Don't think about other things. It's my fault, for living selfishly, after all, we are not isolated individuals and cannot see through the world.

My head hurts so bad, I can't sleep. Too much idleness.

Inheritance already has description objects in quite a few.

Classes are templates.

Enough talk, let’s talk about the template method today.

The template is that the rules are already written, just replace the placeholders with the unique properties of the object.

Let me explain directly to the example.

// abstract class, already owned

abstract class AbstractClass
{

// public abstract void PrimitiveOperation1() that needs personality rewriting
;
public abstract void PrimitiveOperation2();

public void TemplateMethod()
{
PrimitiveOperation1();
PrimitiveOperation2();
Console.WriteLine("");
}
}

// Personalize the implementation on the template

class ConcreteClassA : AbstractClass
{
public override void PrimitiveOperation1()
{
Console.WriteLine("Concrete class A method 1 implementation");
}
public override void PrimitiveOperation2()
{
Console.WriteLine("Concrete class A method 2 implementation");
}
}

//equivalent to replace the placeholder of the template

class ConcreteClassB : AbstractClass
{
public override void PrimitiveOperation1()
{
Console.WriteLine("Concrete class B method 1 implementation");
}
public override void PrimitiveOperation2()
{
Console.WriteLine("Concrete class B method 2 implementation");
}
}

// just references,

AbstractClass c;

//The object represented by the application type

c = new ConcreteClassA();

//When not cast, indicates the method of the reference type.

c.TemplateMethod();

c = new ConcreteClassB();
c.TemplateMethod();

To sum up, the template method is to rewrite the method of the personality, and the other members use the template.

Programming is all about thinking. Inheritance means that the object already has, individualized members, and can be overridden.

It is important to say three times, programmers rely entirely on programming ideas.

Don't talk about it, it's a headache, hey

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325378775&siteId=291194637