Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Which approach?

Name: Anonymous 2011-06-22 22:05

Which approach makes the most sense to you (if any)?

The concern is about enforcing type, and passing references to objects or concrete objects.

Trying to avoid the hazard of passing too many things around by reference, where changes might happen and effect object state from very far away in the code.

However, enforcing everything as a clone seems clumsy.

The real reason to do any of this is to control some property types, because this is being written in a loosely typed language.
Users should be able to trust that a given property being accessed is of the expected class type (and thus, should only be able to set it to that type).


class Type { }

class One__CloneSet_RefGet
{
    private property bar
   
    fun setBar(Type t)
    {
        bar = clone t
    }
    fun getBar()
    {
       return reference bar
    }
}

class Two__CloneSet_CloneGet
{
    private property bar
   
    fun setBar(Bar b)
    {
        bar = clone b
    }
    fun getBar
    {
        return clone bar
    }
}


class Three__RefSet_RefGet
{
    private property bar
   
    fun setBar(Bar b)
    {
        bar = reference b
    }
    fun getBar
    {
        return reference bar
    }
}

class Four__LooseHint
{
    public property bar // can't enforce type
}


// usage




// One__CloneSet_RefGet

b = one.getBar()
b.some_property = true
// one.b.some_property == true
one.setBar(b)
b.some_property = false
// one.b.some_property still true


// Two__CloneSet_CloneGet

b = two.getBar()
b.some_property = true
// two.b.some_property not changed yet
two.setBar(b)
b.some_property = false
// two.b.some_property still true


// Three__RefSet_RefGet

b = three.getBar()
b.some_property = true
// three.bar.some_property = true
three.setBar(b)
b.some_property = false
// three.bar.some_property = false


// Four__LooseHint

lh.bar.some_property = true
lh.bar = true // this isn't good


All ideas appreciated, even if they deviate from these options (the more language agnostic the approach, the better)

Name: Anonymous 2011-06-22 22:08

Oops, noticed an error.

Anywhere where it says setBar(Bar b) should actually read setBar(Type t). The point is that property bar needs to be enforced to be of type Type.

Name: Anonymous 2011-06-22 22:22

Oh, and another thing. Objects by default are passed by reference, so option four solves potentially none of my problems.

Man, fuck this.

Name: Anonymous 2011-06-22 22:34

Thread over, I guess.

Name: OP 2011-06-22 22:38

>>4
Seriously.

It's fucking php.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List