/apex-patterns-strategy

Apex Design Patterns - Strategy

Primary LanguageApex

Apex Design Patterns: Strategy

This repository demonstrates the strategy design pattern implemented in the Apex programming language.

The example exposes a Geocoder search engine that returns the coordinate of a location.

Geocoder geocoder = new Geocoder('GoogleMaps');
Double[] location = geocoder.getLatLong('Moscone Center'); //=> [37.7845935,-122.3994262]

The service can use different strategies to retrieve the result. We provide mock implementations for GoogleMaps or MapQuest. The available strategies are defined as a comma delimited list in a My_Settings__c custom settings list.

Check out the GeocoderTest test class to see how to use the service.

Installation

Create a scratch org:
sfdx force:org:create -a pattern -s -f config/project-scratch-def.json

Push source to scratch org:
sfdx force:source:push

Run Apex tests and get code coverage:
sfdx force:apex:test:run -c -r human -w 10