function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gokubigokubi 

Static and OO vs. Procedural

I'm working on converting a lot of S-Control functionality to Apex. We're trying to keep triggers as simple as possible and move logic to classes to facilitate code reuse.

There seem to be two ways to reference code in classes. One is to instantiate the object and then use it:

        DefaultAccount defAccount = new DefaultAccount();
        Id DefaultAccountId = defAccount.getDefaultAccountId();

The other is to make the methods Static and call them without instantiating the object:

        list<Account> AcctsToUpdate = MembershipRollup.RollupToAccounts (AcctsToProcess, mbrRTids);

By using Static, do we risk problems if two processes access that class at the same time? My understanding of Static is that multiple use of those resources will share the same memory location, which would be bad. Is that the case, and should we go to instantiating the objects?

Or is it just a preference issue and either way will provide similar results?

Thanks,
Steve