You do not need to create new objects for a class to implement a single call.

Source: Internet
Author: User

In a recently created Project, a backend service is written, and many new objects are created in different methods in the demo to call the service, this is a normal thing for my new employee. However, after reading this, my project manager said that this would cause unnecessary waste of system resources, therefore, I am taught a simple method so that I don't need to create a new object every time to implement the call, and add

Public static octopusgameservice Service
{
Get
{
If (service! = NULL)
Return service;
Else
{
Object o = new object ();
Lock (o)
{
Service = new octopusgameservice ();
}
Return service;
}
}
} The method of my service is similar to that of others. In this way, all methods of the service can be called as long as the service is called, thus avoiding the creation of new objects for calling.

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.