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
t.sellst.sells 

Object Oriented Apex

I am coming from a .NET environment, and I am having some trouble with the OO particulars of Apex. I want to create a class that is extended from a base class that implements an interface. In my example, the interface, base class and class are in separate files.

My main question is in regards to accessing functions and variables in the base class. Since I have to explicitly reference the base class name and the function (which has to be public?) what is the point of using the “extended” modifier, since I can accomplish the same without it? Also, I really want the base class variables and to be private, or at least protected, in the implementation of the interface, but it doesn’t allow me to do that.

Any links, references or advice would be greatly appreciated. Thanks!

- Todd

public interface SC_IProcess {
	void execute();
	void initialize();
}


public with sharing virtual class SC_ProcessBase implements SC_IProcess {
	
	public static sObject somesobject; 	
		
	public virtual void execute(){
		
	}
	
	public virtual void initialize(){
		
	}
	
	public static void UpdateValues(){
		system.debug('Updating Values');
		upsert somesobject;		
	}

}


public with sharing class SCTemplate extends SC_ProcessBase {
	public void SCTemplate(){
		initialize();
		execute();
	}
	
	public override void execute(){
		SC_ProcessBase.UpdateValues(); 				
	}
	
	public override void initialize(){
		somesobject = new account(name='my name');	
	}
}

 

 

 

Mayank_JoshiMayank_Joshi
Hi ,

In Apex, by default all access modifiers were Private . Untill ,we explictly defines it as Public Or anything else .

Refer this link please : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_interfaces.htm