Spring. Net study note 11-custom object behavior (basic)

Source: Internet
Author: User

Spring. net {
Function onclick ()
{
Tagshow (Event)
}
} "> Interface to control the behavior of objects in the container. When it comes to object behavior, we need to mention the object lifecycle control. Similar to winform development, in the form lifecycle, the load method is the loading method of form and the dispose method is the destroy method of form. Spring. Net can perfectly meet these needs.

I. lifecycle Interface

When using spring. net {
Function onclick ()
{
Tagshow (Event)
}
} "> How to initialize and destroy a framework {
Function onclick ()
{
Tagshow (Event)
}
} "> The following solutions may help you with the trouble of hosting resources (such as database connections.

1. Initialization

Inherit the spring. Objects. Factory. iinitializingobject interface or {
Function onclick ()
{
Tagshow (Event)
}
} "> Configure the init-method attribute of the object node. The IOC framework of spring. NET will call the configured initialization method after the object is instance.

2. Destruction

Inherit the system. idisposable interface or configure the destroy-method attribute on the object node. Spring. NET will call it when the container is destroyed.

Implementation Code:
Person

  1. Public class person
  2. {
  3. Public void Init ()
  4. {
  5. Console. writeline ("I have grown up ");
  6. }
  7. Public void destroy ()
  8. {
  9. Console. writeline ("I am aging ");
  10. }
  11. }
  12. <! -- Lifecycle interface -->
  13. <Object ID = "person" type = "springnetprocessor. Person, springnetprocessor"
  14. Init-method = "init" Destroy-method = "Destroy"/>

Copy code


Ii. Definition of abstract objects and sub-objects

The object definition may contain a large amount of information, such as container-related information (such as the initialization method and static factory method name), constructor parameters, and attribute values. A sub-object definition is an object definition that inherits configuration data from a parent object definition. Sub-object definitions can be rewritten or added as needed. Defining the parent object and sub-object may save a lot of input work. Actually this is {
Function onclick ()
{
Tagshow (Event)
}
} "> In design mode {
Function onclick ()
{
Tagshow (Event)
}
} "> Template mode. In my opinion, the coupling between "subclass" and "parent class" can be solved.

Set the parent attribute in the object node to indicate that it is an inheritance relationship rather than an inheritance of positive meaning.

Implementation Code:

  1. <! -- Abstract object definition and sub-object definition -->
  2. <Object ID = "parent" type = "springnetprocessor. Parent, springnetprocessor" abstract = "true">
  3. <Property name = "name" value = "parent"/>
  4. </Object>
  5. <Object ID = "child" type = "springnetprocessor. Child, springnetprocessor" parent = "parent"/>
  6. Public abstract class parent
  7. {
  8. Public string name {Get; set ;}
  9. }
  10. Public class child
  11. {
  12. Public string name {Get; set ;}
  13. }

Copy code

We can see that the Child class does not inherit the parent class.

Output result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.