开发者

What to name this class?

开发者 https://www.devze.com 2022-12-28 03:51 出处:网络
(This is not an interface: I simply omitted the method bodies) class _ { protected $_data = array(); function __c开发者_StackOverflowonstruct($data);

(This is not an interface: I simply omitted the method bodies)

class _ {
    protected $_data = array();

    function __c开发者_StackOverflowonstruct($data);

    function set($name, $value);

    function get($name);

    function __set($name, $value);
    function __get($name); //aliases for their respective non-magic methods.

    # and some other generic methods
}

Essentially it's a class that provides a magical object-oriented reusable access layer to some data. I've considered DataLayer, DataObject and some others; I'd like to hear some suggestions from someone who's more terminologically savvy.


How about Dave ;)

Seriously though, what about DataAccess


Without knowing how the class is used and what data it's meant to wrap, it's hard to name it. "Wraps some data in magic OOP" is so generic that a meaningful class name is difficult.

If it's for sitting between the controller and the database, you could call it ActiveRecord.

If it really is just for providing some OOP syntactic sugar to an array(), you could simply use the built-in StdClass.

Failing that, given that the only purpose of the class seems to be to wrap an array, I'd be tempted to call it ArrayWrapper.


There's a class like that in Magento. Well, it's got a lot more stuff in it, but the philosophy is the same: add some magic method goodness to the rest of your classes via inheritance. They named it Varien_Object, Varien being the name of the company.

I've also got something like this in a custom framework I've helped build. It's just called Base.

I guess what I'm trying to say is... no matter what you call it, it wont help people understand what it does until they go through the code. Don't worry about it too much, by the time you're done it'll be buried so deep in your app that the only people that find it will be the kind that can grok what it does fairly quickly anyway


You could call it AccessLayer.


It really resembles KeyPairValue and if you with to make it more specialized in defining how Get would find its entries say using a Hash() function, then it's a Hashtable.

  • class KeyPairValue
  • class Hashtable

Now the question is why? Most SDKs would offer such data structures?

Try to use existing structures and not re-invent them.

0

精彩评论

暂无评论...
验证码 换一张
取 消