From http://www.cnblogs.com/wzcheng/archive/2007/07/31/837199.html
In the morning, check the branch method of. NET Framework 3.5. For example, the first class is the definition class, and the second and third classes are the implementation class.
Public partial class AI
{
Public void active ()
{
This. Run ();
This. Jump ();
}
Partial void run ();
Partial void jump ();
}
Public partial class AI
{
Partial void run ()
{
Console. writeline ("I am running ");
}
}
Public partial class AI
{
Partial void jump ()
{
Console. writeline ("I'm jumping ");
}
}
It can:
1. The above three classes can not be placed in the same CS File
2. If the last two branch classes are not written, the compilation will pass smoothly. In Il, run and jump with method bodies will be generated, but empty implementations will be implemented.
It cannot:
1. The division method cannot be public or private.
2. The implementation class and the definition class cannot exist in different programming sets.
Its value is as follows:
1. More detailed division of labor process. In the past, system analysis was conducted to the object level, and now the method level can be further subdivided. In the example, the object framework maintainer defines the active method, and run and jump may be assigned to others for implementation.
Such a division of labor model is closely related to the trend of large-scale integrated development. Simply put, this is just a new language feature; think carefully, it is actually a signal of software development towards industrialization. In the future, the software development process will be completed on the production line based on more features (or development processes. A person is a screw, so that you can run and jump. If you want to make full use of your talents, you can make full use of it!
2. the code can be written more elegantly. If the internal implementation of run and jump in this example is extremely complicated (AI robot behavior), a CS file can contain tens of thousands of lines, others vomit blood when reading. If you encounter a code writing that is not authentic and the method is piled up, it will even leak out the liver. With the division method, you can press the problem to a local location, and I can't see it if I don't want.
3. Code elegance is just a representation. If performance is sacrificed, I would rather not have this feature. In fact, on the contrary, the efficiency of the division method is very good. Write an example for details. Observe Il. Haha!
# C # column