Naming suggestions

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Naming suggestions

Post by alex.barylski »

Ok, I have an class which has the following methods:

Code: Select all

class Context{
  function registerContextData($ctx);

  function getInstance($id);

  function createAllInstances();
}
Firstly this is just a mockup, the actual implemention is in Javascript...

getInstance($id); is a factory method which returns the appropriate type of object according to details given when that objects information was registered via registerContextData()

registerContextData($ctx); is called each time a new object is required to be built.

createAllInstances() is called automatically by the framework...

Now this is just a rough draft and may completely change, as I haven't worked out all the quirks of dealing with javascript and the DOM...

It's hard to explain fully what I am trying to do, so please read and understand the best you can before firing off suggestions...

The class itself is a singleton, acting much like a Windows process and getInstance() is a factory which (doesn't actually build but..) returns existing objects created when appropriate by the framework by calling createAllInstances()

To stick with the analogy getInstance() would be returning something of a thread...but the threads are not created by calling getInstance() but rather by registering a "context" structure (actually an object) with the framework calling registerContextData() and then later, when the framework determines the "threads" can be created, it actually creates the instances of the threads by calling createAllInstances()

This is not a proper design type question...as like I said it's still rough draft and is a improved version (at least the direction I'm heading) of the TinyMCE_Engine class

Yes I'm re-writing a WYSIWYG editor... :P

Likely make it open source...anyone else care to help??? :)

Anyways, knowing all of the above...what kind of "name" would you give the class?

I can't decide, currently I have the following:

MyEditor_Interface - As it's a singleton, which provides an abstract base class (interface & implementation) for a subclass

I refer to an interface as a special kind of class which is intended to be derived from and cannot be instantiated, much like an ABC. However in this case, an interface would also provide some minimal implementation. Basically what I defined above...

It's an interface (contains the data members used in subclass) to a subclass, but also acts as a class in that it encapsulates instance functionality...

MyEditor_Instance as the interface/class also is the class responsible for handling a single editor instance. An editor will have sub-editors which are returned via the getInstance() factory method...

MyEditor_Engine The one I most dislike as it's already used and not very well modelled IMHO...

So...design opinions, naming opinions, etc...???

Interface or Instance? Has a subclass called MyEditor_Control currently, but I think that will soon change to something else very soon...

Cheers :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Use whatever name you like at the moment. Later on, you can change it. The only time changin the name of a class becomes painful (and only in a rough sense) is when you already have releases in the wild. Even then, you just release a compatibility file to include if the user is using "xy" instead of "yx" version.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Edit: Nevermind no the naming issues...I got it :P However feel free to contribute still... :)

Obviously it's not stopping development :P

However it does keep me coming back to put some thought into it...and I'd rather just name it and continue...without worries forever and ever...

I say this, as the control will not likely grow into anything more than that, in fact I gaurantee it :)

Like every project I start I try and find similarities to existing frameworks like MFC/OWL, etc...and I typically steal ideas and design strategies from that and go with it...

Now after some more though, the class is more analogous to a CWinApp object...problem is...it's not an application...nor an instance of...

I'm sorry if I sound anal...first with conventions and now naming of classes, etc...but like Shakespeare, I am a poet of the binary world :P

"What's in a name? That which we call a rose
By any other word would smell as sweet."


The art and science behind software development fascinate me :)

Cheers :)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Sounds like a registry to me.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Hey AC, thanks for the indepth reply :P

Just kidding amigo, any input is appreciate terse or not :)

Anyways, although my understanding of design patterns has mostly been accumulated through osmosis, I would have to argue that it's not a Registry...

But as I've said, my understanding may not be accurate, I'll read up on that again maybe...

Was that a suggestion for a name? If so, I failed to mention that I don't like using design pattern names for variables, or anything in the namespace, unless it's the name of the actual object...

For instance, when I manipulate the Windows registry, I use the namespace Registry...

I was looking more the for name of the actual object I was modeling then the technical name for the object, if that makes any sense... :P

The reason being is design pattern names are esoteric and possibly misleading like in the example I gave above... :)

Quick question regards to Registry...

I understand it, a registry is basically an object API to replace globals (personally I have zero problems with globals, but meh....) much like a stash which is basically a container array for any object you can imagine...

Knowing this, it doesn't make sense to derive from a Registry??? Would you say this is true? According to official descriptions? I would think, best practice would say to instantiate a singleton registry as a single global and store each global in the Registry instead...???

Just curious...

Cheers :)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

It is a registry, in the same terms of the windows registry.

As you'll be aware, when interogating the windows registry, you provide it with a key and it returns a value if it has one corresponding to that key.

Same applies for the Registry pattern. The fact it is most often used to store Objects is neither here, nor there.

The Singleton pattern is often confused/combined with the Registry because in 99% of all cases, the Registry will/must be a singleton.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Jenk wrote:It is a registry, in the same terms of the windows registry.

As you'll be aware, when interogating the windows registry, you provide it with a key and it returns a value if it has one corresponding to that key.

Same applies for the Registry pattern. The fact it is most often used to store Objects is neither here, nor there.

The Singleton pattern is often confused/combined with the Registry because in 99% of all cases, the Registry will/must be a singleton.
What I have modeled I am quite certain is not a registry, I'll give you an example if you like...

As for Windows registry being a registry...ok fare enough...although I was always under the impression a registry was not persistent, whereas Windows registry is...whether that's where M$ got the name from or some other kind of coincidence is neither here nor there :P
The Singleton pattern is often confused/combined with the Registry because in 99% of all cases, the Registry will/must be a singleton
That's not what I was asking, as I'm aware of the differences between the two... :D

What I was asking is if it's common practice to derive from a registry...as IMHO and from what I understand...a registry would make more sense implemented as a singleton object.

The Windows registry is more analogous to a persistent registry, like a registry pattern implemented with sesion support or something more persistent like DB, etc...

Cheers :)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

On second thought, the fact that the object currently appears to take input and allow it to be used later, would indeed give it the appearance of a Registry :P

My bad for missing that much...although it's not strictly a registry I promise...as it does have a method which is somewhat like a factory method...and would be best implemented as a singleton, as I would only ever need a single instance...

This hodge podge of patterns is why I am having a hard time accepting one over the other...Maybe I'll juyst call it a Hybrid :)

Anyways, thanks for the input and making me rethink what I've said...as "in a way" it is indeed a registry, but also more :P

Cheers :)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Having read more throughly your original post, this sounds very familiar to Reflection. Though I'm no expert..
Post Reply