Showing posts with label Class. Show all posts
Showing posts with label Class. Show all posts

Saturday, October 17, 2009

OOP Semaphores
Byline: Smoke signals from one developer to another.

I would like to point out the very obvious, that too often gets lost in the shuffle.  The code choices we make when designing components act as a series of “signals” that we send to the next developer working on the library or to the developer who is applying and implementing the objects we have created.  When we are crafting our code, our choices of class and parameter names, member protection levels, and constructors act as the primary method of disseminating the indented usage of our code.

If an organizations code base is the most inclusive repository of business process knowledge of an organization, then our code libraries supply the nouns, verbs, and adjectives of the business process.

Name for global business understanding
Most business processes have a generally accepted internal name.  This is the name that the stakeholder community will call something when telling their business story.  Using a different name, as in the statement, “to me blank is this,” when your user community has consolidated on a defined designation, is obfuscation, and to me, smacks of hubris.

Sometimes, you must rename, for elucidation, like when swapping out an acronym or abbreviation for a “Plain English” term that more fully explains the intended usage.  But this means you will have to disseminate the new term and usage throughout the hierarchy you are involved in.

One of the best reasons I can think of to develop documentation artifacts before the creation of a code base, is so that you have a more complete set of thoughts on the business processes, so that the names you choose will be indicative of the actual use of your objects in the wild.

Code the meaning of your Intended Usage into your implementations
So lets talk about the following code:
  
 Fig.1  
    interface iAnimal
    {
        string Name { get; set; }
        object Vocalize(object SpeechType);
    }



The Plain English meaning of this code is that all objects that implement iAnimal will have at least one string type property called Name, and a method called Vocalize that takes a parameter of type object and returns an object.  By creating an interface (a code pattern that set a base contract of what will be contained in an object) the architect of the code, signals to other human beings implementing his work, that this is the minimal acceptable level of code to implement this functionality.  If you implement from this interface, the assembler will only compile your object, if your code object contains all the members specified in the interface. Those the contextual meaning of the code is “you must have all these pieces.”

Fig.2
    public class Animal : iAnimal
    {
 private object _vocalization;       
 private string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
       
        public object Vocalize()
        {
            return _vocalization;
        }

    }


Figure 2 shows the terms of the code contract being met in full. So we have a cycle of intention and usage, playing out into fulfillment, Contract spelled out by the interface, and then Contractual Obligations met in full by the implementing class.

“What I would like to stress here, is this is not just a series of assembly instructions, this has inherent intended meaning from one human being to another”
So how about when a developer sets up a class as abstract, the Plain English meaning is that the object must be inherited to be used. The compiler will not build if you try to call new on the abstract object.  But the contextual meaning that the code’s architect is attempting to send to the implementing developer is that the architect’s intended usage of this code is as a base class that is meant to be inherited.

Wednesday, June 18, 2008

Memes as Class Objects

I am interested in the idea of the Meme, because it appears to behave in a manner very similar to a Class. A meme is a container that may contain any amount of meme inside of it. A meme as a knowledge unit suggests a discrete action that it accounts for. A meme may have properties.

A Meme, as a transferable knowledge unit, would consist of at least one noun and one verb. This would correlate to properties and methods in OOP.

It would appear to transfer well as a method of capturing work-flow into an object oriented class structure.

Sunday, June 15, 2008

Class-Responsibility-Collaboration hierarchies in databases

Database Structure is the rules of how an organization's data interacts together. This may seem obvious, but if you look at designs of databases and development, you see that the obvious is often ignored when in context. The database structure is the Meta Data, the data that explains data.

An organization, from where I sit in the back office “virtually” consists of a network skeleton that reaches across to nodes, and or satellites. A backbone of heavy iron churns that data and runs the processes, launched by request from workstations.

Usually an organization will have one or many databases that act as the repository of information in an organization. The purpose of this data is to monetize the information or processes for profit.

The way to think about the database is not to view it as a dog-pile of stuff, but to think of knowledge units. Many knowledge units are contained in the database and linked through processes and/or relationships.

Knowledge units are first understood through the analysis of existing (or new) business practices. This often is done through “Use Case” scenarios. These knowledge units are transformed (part of the problem?) into “machine Instructions†” by a programmer.

Knowledge Unit storage in the database, is the combination of data and the applied rules to the data in conjunction with the relationships that data has with other data (a variety of rule).

Yet, what so often happens in production of a database design, is too much of the design is set up because, “I need to store this somewhere,” and a table of codes is created. The structure reflects the needs of the designer at design time, but does not take into account that what needs to be stored are things from the real world. These knowledge units are digital depictions of a real world objects or processes. The real world intrudes on the digital with Class-Responsibility-Collaboration hierarchies, but too often the immediate needs of a program result in structures being created on the fly that are nonsense.

So what I am saying is that when we are storing data into a database, we are storing the digital representation of a real thing, a classification or series of actions. To miscellaneously toss this willy-nilly into a hierarchical structure risks moving the whole structure into a game of “Silly-Buggers.”




†Usage for me is anything set of instructions a computer can use to render results, i.e. Table relationships, SQL statements for data extraction, script or compiled code, ect.