On 18 December 2012 15:11, Ollie Castle <
oliver...@tribeguru.com> wrote:
> The person personRepository so we check if it is nil before creating the
> object.
>
>>
>> personRepository = new(PersonRepository)
>> func GetPersonRepository() *PersonRepository {
>> return personRepository
>> }
>
>
> If I was to do it in C# it would be.
>
>> private PersonRepository personRepository;
>>
>> public PersonRepository PersonRepository
>> {
>> get
>> {
>> if (personRepository == null)
>> {
>> personRepository = new PersonRepository();
>> }
>> }
>> }
>
>
> I am just unsure how to achieve this in go
I'm not quite sure if this matches up to your question, but
something like:
type YourTypeName struct { pr personRepository }
func (t *YourTypeName) PersonRepository() {
if (
t.pr == nil) {
t.pr = MakeAPersonRepository }
return
t.pr
}
Note that Go's new function is NOT like C#s; it returns a pointer
to a zero-value of the given type, not calling any implicit
constructor function (because Go doesn't have them).
Chris
--
Chris "allusive" Dollin