-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: RedSunBeer
Message 1 in Discussion

 Discover the objects and classes in your application [For those who can't code or 
design] 
Terminology:<o:p></o:p> 
OOAD: object oriented analysis and design<o:p></o:p> 
OOP: object oriented programming.<o:p></o:p> 
Class: A set of code defining the behaviour of an object.<o:p></o:p> 
Object: An entity that can be created from a class by instantiating the 
class.<o:p></o:p> 
Instantiating: This is the action that creates an object from a class when a program 
is executed.<o:p></o:p> 
 <o:p></o:p> 
Introduction: <o:p></o:p> 
This article is for programmers, testers, business analysts, architects, designers as 
well as students, computer/software users and people who feel a need to understand 
software design and development. Therefore this article will try to explain the design 
of objects in software as best as it can without using too many technical terms. Both 
techies and non-techies would find this non-technical approach useful as it separates 
the concepts from the actual coding issues.<o:p></o:p> 
 <o:p></o:p> 
Objects:<o:p></o:p> 
Normally what do we consider an object to be? It is usually something that has mass, 
shape, volume and is visible. So we think of a pencil or a hammer as an object. But we 
don�t think of an electric field, as an object as it doesn�t have mass, shape, 
visibility or space that are perceived by our human senses. But in programming even an 
electric field could be an object. Let us study this case in more detail.<o:p></o:p> 
 <o:p></o:p> 
Consider a pencil. We can see, feel and even smell a pencil. It has characteristics 
like weight, color, size, and shape. It even has parts like the lead, the eraser on 
its top end and the wood in which the lead is embedded. The parts too have 
characteristics like the color of the lead, the paint on the wood and length and 
width. We can perform actions with it like writing, scribbling, sketching and shading. 
All these factors contribute to the pencil becoming an object.  On the other hand the 
electric field is invisible, has no smell, taste and cannot be felt. But with special 
equipment we could determine the intensity, range of influence, direction, source and 
several other characteristics. The electric field may perform actions like creating a 
magnetic field in a steel object (similar to a pencil performing writing).  Therefore 
we could create a class called ElectricFieldClass that reflects the behaviour of an 
electric field.<o:p></o:p> 
 <o:p></o:p> 
In a general software application, a 'business' object must have characteristics (in 
programming terms properties and attributes) and it may have methods and events. In 
OOP though you could also create an object by simply instantiating its class. This 
concept is not of much relevance for business objects.  <o:p></o:p> 
 <o:p></o:p> 
The parts of the pencil (which is the object) are called components in programming 
terms. Each of the parts, like the pencil's lead for example has its own 
characteristics. Depending upon the type of pencil the lead could actually be made of 
other material like graphite, it may be soft or hard, the thickness may differ and 
length of the lead could vary too. An object should normally have a purpose. So the 
purpose of a pencil could be to write, sketch, doodle, color etc. This purpose is 
achieved by doing some action like writing, sketching, doodling, coloring etc. The 
actions that an object can perform are called methods in programming. The methods of 
an object are usually associated with the class that defines the object. When an 
action is performed an event can be associated with it.  An event is a software entity 
that is triggered when the action it is associated with occurs. If we use the pencil 
to write, an event called 'OnWriting' could be created to let a listener know that the 
action occurred. A listener in other words is a code/process that is executed when an 
event is fired. Similarly 'OnStartWriting', 'OnEndWriting' identify that writing has 
started and ended respectively. The attributes, methods and events all contribute to 
the behaviour of a class.<o:p></o:p> 
 <o:p></o:p> 
Classes:<o:p></o:p> 
To create objects in programming we use classes. The classes serve as templates that 
contain the attributes (characteristics), methods (actions) and events (actions 
performed) of the object to be made. From the software perspective the pencil as a 
whole is an object and again the parts of the pencil (components in programming terms) 
could be objects too. To create a pencil we could proceed as follows. First we define 
a class called PencilClass.  We then decide the most basic features of the pencil (the 
attributes or properties) of the PencilClass. The basic feature of the pencil would be 
the lead and the lead holder. Without these two features the pencil would not be a 
pencil. So the basic requirements of a pencil are defined in a class (PencilClass) 
having two basic attributes namely the 'lead' and the 'leadholder'. <o:p></o:p> 
 <o:p></o:p> 
The other parts of the pencil like the eraser, the eraser holder and other add-ons are 
optional and depending upon our requirement we could add or remove these parts. 
Therefore we do not include these attributes in the basic class (or base class) to 
define a pencil. But another class that gives more definition to it may extend the 
base class. So in another class say 'ColorPencilClass' we could extend the PencilClass 
(ie the base class in this case) with attributes that are available in pencils used 
for coloring. So do not simply extend the PencilClass in a ElectricFieldClass unless 
they have some common behaviour between them.<o:p></o:p> 
E.g. 'Pencilcolorname' can be an attribute of the class ColorPencilClass that 
identifies the pencil by a color name. <o:p></o:p> 
This characteristic could be of more significance for a color pencil than for a 
writing pencil. The ColorPencilClass itself does not define the basic attributes 
required for a pencil. Instead we 'inherit' the PencilClass in the ColorPencilClass. 
In doing so the attributes of the PencilClass are made available in the 
ColorPencilClass without having to define them again. In this case the PencilClass 
plays the role of the base class and the ColorPencilClass becomes the derived class. 
In the same way the PencilClass could be inherited by another class say the 
'WritingPencilClass'. This way the WritingPencilClass would have the attributes of the 
PencilClass as well as its own attributes. The main idea behind inheriting a class is 
to separate the basic common features of a group of related classes. The class that 
inherited from the PencilClass is called the derived class. The derived class extends 
(i.e. adds more definition to) the base class.<o:p></o:p> 
 <o:p></o:p> 
The pencil's lead and  lead holder are components of the pencil object with their own 
features and are treated as separate objects. The 'LeadClass' may have attributes like 
length, thickness, hardness, material (lead, graphite, other). The 'LeadholderClass' 
may have attributes like material (wood, plastic, steel), length, width, color and 
shape. Both these component classes are used as attributes of the 'PencilClass'. We 
could even identify other subcomponents. For example the material of the 
LeadholderClass could itself be an object having its own attributes and could 
therefore be treated as an object by itself. To decide on what objects  (and their 
classes) are required would invlove a proper understanding on how exactly each object 
fits into the general scheme of things (i.e. the requirements software application or 
system we are trying to design). As a thumb rule an entity that has attributes could 
be a candidate for an object.<o:p></o:p> 
 <o:p></o:p> 
When we buy pencils are our requirements change depending upon the purpose of buying 
the pencil. A draftsman would give more importance to the lead provided while a little 
child would be more concerned with the physical appearance. Similarly in software if 
the object is going to be used to manufacture pencils, then each part and sub part of 
the pencil would need to be defined clearly and in greater detail. This would mean 
that each component would be an object and have its own class. But if the software was 
used to purchase a pencil for a regular office use then the details could be defined 
more simply. Instead of defining the 'lead' and 'lead holder' as separate objects we 
could simply make them attributes in the PencilClass (say 'PencilType'). The 
'PencilType' could have different values like 'Fine', 'Regular' and 'Ordinary'. 
<o:p></o:p> 
 <o:p></o:p> 
Below are some of the classes to create pencil objects<o:p></o:p> 
�         Class name: SimplePencilClass<o:p></o:p> 
Attributes: Lead, Leadholder, Length, Width, Color, Weight.<o:p></o:p> 
Methods: Write, Draw, Render<o:p></o:p> 
Events: OnStartWriting, OnEndWriting, OnWriting<o:p></o:p> 
�         Class name: AdvancedPencilClass<o:p></o:p> 
Attributes: (object) Lead, (object) LeadHolder, Color<o:p></o:p> 
Methods: Write, Draw, Render<o:p></o:p> 
Events: OnStartWriting, OnEndWriting, OnWriting<o:p></o:p> 
�         Class name: ColorPencilClass inherits PencilClass (or 
AdvancedPencilClass)<o:p></o:p> 
Attributes: Colorname<o:p></o:p> 
Methods: Draw<o:p></o:p> 
 <o:p></o:p> 
If the parent class gives access to its members the ColorPencilClass would also have 
the attributes, methods and events of its parent class by default. The Draw method in 
the class ColorPencilClass would override (supercede) the same method in the base 
class and instead apply its own implementation of this method.<o:p></o:p> 
 <o:p></o:p> 
Identifying objects in an application:<o:p></o:p> 
Consider an application that helps students register for courses. Most registration 
forms would have sections for personal details, address, educational details, contact 
details and referrals. Let us take a closer look at the address part. The address part 
of a application would typically contain details like building number, street name, 
block/locality name, town/village name, district/county name, state/province name, 
country name and zip/pin code. We could have a class for the address portion alone say 
'AddressClass'.  Now each item of the address section in the registration form could 
be treated as an attribute of the AddressClass. Again looking at each detail we may 
think that items like town, state and country could be objects themselves. This 
depends upon the role of these objects in the registration application project. If 
each of these items could have several attributes, then they could become candidates 
for objects too. Assume that the item 'state' has attributes like state identity, 
state name, and country identity. By making it an object we would also facilitate 
future additions to the state like the state area, state population, state language 
and state ranking. On the other hand many registration applications do not require 
that the item 'town' have any extra details besides the town name. A simple text entry 
for the town does this. Here the town does not need a unique identity or be mapped to 
a state and there is no possibility of adding more attributes in the future. Therefore 
the town could be an attribute of the AddressClass and not another object by 
itself.<o:p></o:p> 
 <o:p></o:p> 
Summary:<o:p></o:p> 
It is essential to identify classes and objects with respect to the application you 
are developing and not merely to real life situations or by imitating other 
applications. Understanding the business requirements of the applications would be the 
ideal starting point to identifying objects.<o:p></o:p> 
 <o:p></o:p> 
  
<o:p>note: I hope that others would take this discussion forward. </o:p>

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to