Open Source - data base managnment system - Asked By Hafiz Ullah on 20-Nov-11 08:44 AM

One by one short definition with Example
what is Entity.
what is attribute.
Suchit shah replied to Hafiz Ullah on 20-Nov-11 09:28 AM
What is Entity ?
Entity is a thing in the real world with an independent existence. and entity set is collection or set all entities of a particular entity type at any point of time. 
take an example:
a company have many employees ,and these employees are defined as entities(e1,e2,e3....) and all these entities having same attributes are defined under ENTITY TYPE employee.and set{e1,e2,.....} is called entity set.
we can also understand this by an anology .
entity type is like fruit which is a class .we havn't seen any "fruit"yet though we have seen instance of fruit like "apple ,banana,mango etc.hence..
fruit=entity type=EMPLOYEE
apple=entity=e1 or e2 or e3
enity set= bucket of apple,banana ,mango etc={e1,e2......}

What is Attribut?
 An attribute is a property or characteristic. Color, for example, is an attribute of your hair. In using or programming computers, an attribute is a changeable property or characteristic of some component of a program that can be set to different values.An object or entity is characterized by its properties or attributes. In relational database systems attributes correspond to fields.

dipa ahuja replied to Hafiz Ullah on 20-Nov-11 10:21 AM

The Entity

In clinical data, the entity is typically a clinical event, as described above. In more general-purpose settings, the entity is a foreign key into an "objects" table that records common information about every "object" (thing) in the database – at the minimum, a preferred name and brief description, as well as the category/class of entity to which it belongs. Every record (object) in this table is assigned a machine-generated object ID.

The Attribute

In the EAV table itself, this is just an attribute ID, a foreign key into an Attribute Definitions table, as stated above. However, there are usually multiple metadata tables that contain attribute-related information, and these are discussed shortly.

http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model#The_Entity

aneesa replied to Hafiz Ullah on 20-Nov-11 10:47 AM
* An entity is an object that exists and is distinguishable from other objects. For instance, John Harris with S.I.N. 890-12-3456 is an entity, as he can be uniquely identified as one particular person in the universe.

* An entity may be concrete (a person or a book, for example) or abstract (like a holiday or a concept).

* An entity set is a set of entities of the same type (e.g., all persons having an account at a bank).

* Entity sets need not be disjoint. For example, the entity set employee (all employees of a bank) and the entity set customer (all customers of the bank) may have members in common.

* An entity is represented by a set of attributes.
o E.g. name, S.I.N., street, city for ``customer'' entity.
o The domain of the attribute is the set of permitted values (e.g. the telephone number must be seven positive integers).

* Formally, an attribute is a function which maps an entity set into a domain.
o Every entity is described by a set of (attribute, data value) pairs.
o There is one pair for each attribute of the entity set.
o E.g. a particular customer entity is described by the set {(name, Harris), (S.I.N., 890-123-456), (street, North), (city, Georgetown)}.



programming foundamental - Najeeb Ullah replied to aneesa on 22-Nov-11 07:45 PM
Short Answer with Example.
Q1:- why it prohibited to goto statement
aneesa replied to Najeeb Ullah on 24-Nov-11 02:18 AM

when (not) to use the goto keyword


This article discusses some common usage scenarios of the goto keyword and shows alternative approaches.

 

goto comic from xkcd.com

comic by xkcd.com ^


If someone would have asked me a few years ago when to use the goto keyword I would have answered (in capital letters): NEVER!! GOTO’S ARE EVIL!(and obviously you get attacked by raptors if you use them)

Like many I have been educated to have a emotional reaction when someone mentions the goto keyword. Emotions have nothing to do with good practices, so lets take a pragmatic look on some of the common usages of goto and see what the real value of the goto keyword is.

Using goto to provide a single exit point.

The author of Sams Teach Yourself C# in 24 Hours (published by O’Reilly) describes the usage of gotos like this: (code slightly modified to make it more readable)

[...]This discussion may leave you wondering why you would ever use goto. One situation in which I commonly use goto’s is to create single exit points. As you know, you can force execution to leave a method at any time using return. Often, clean-up code is required before a method exits. In a long method, you may have many return statements. However, such a method can be a problem to debug because clean-up code may not be run under all circumstances. Because all methods have a single entry point, it makes sense to give them a single exit point. With a single exit point, you use a goto statement to go to the exit point, rather than use a return statement. The following procedure illustrates using goto to create a single exit point:

private void btnGoto_Click(object sender, System.EventArgs e)
{
//...
// If it is necessary to exit the code, perform a goto to
// the PROC_EXIT label, rather than using an Exit statement.
if (someValue)
goto PROC_EXIT;
//...

PROC_EXIT:
//...
return;
}

The author suggests using gotos for cleanup code and to provide a single exit point. This seems logical and it might be the most common use of gotos, it is however in C# absolutely unnecessary. (I guess if someone wants to learn C# in 24 hours there is no time to learn it the ‘right’ way.) To force cleanup code we can and should use a simple try finally pattern (read more about it in my article).

We can rewrite the code above to this

private void btnGoto_Click(object sender, System.EventArgs e)
{
//...
try
{
//... (can even contain return statements or throw Exceptions)
}
finally
{
//cleanup here
}
}

This approach has two major advantages:

  1. you don’t have to remember to use goto instead of return

  2. the cleanup code is executed even if there is an exception thrown

Using goto to jump between switch statements.

Coming up with a reasonable example for a goto in a switch statement has proven to be difficult, which in itself might be an indicator for its usefulness. Anyway, basically you can jump from one case in a switch code block to another using the goto statement.

switch (something)
{
case 1:
//some code
goto case 2;
case 2:
//some code
if (someExpression)
goto case 1;
//some more code
goto case 4;
case 3:
//some code
break;
case 4:
//some code
goto default;
default:
break;
}

Let’s just take a look at this code snippet to discuss some of the upsides and downsides of goto statements in a switch code block. One good thing with labels in the switch statements (case 1, case 2 ect.) is that they are only accessible within the scope of the switch statement, which means that you cannot jump into the switch statement. This makes it easier to read but as you can see in the example above it makes it more complicated to follow the execution since it is no longer linear. Especially if the switch block is longer than a page and you use conditional goto’s (such as the one in the if (someExpression) block) it can be a real challenge to follow the execution flow. Unfortunately there is nothing to prevent you from defining a loop in which case the program will cause a StackOverFlowException. In the example above the goto case 1 in case 2 sends it back to case 2 and it could potentially be send back to case 1 again creating a loop. I would suggest to be open for the usage of the goto statement in switch blocks unlesst he complexity is high enough to make it painful to debug or there are possibilities for loops.

Using goto to break out of nested loops.

Another popular usage of gotos is breaking from nested loops. Unfortunately there is no break all keyword that would help us to break out of nested loops so we have to find another way of doing this.

for (int i = 0; i < 25; i++)
{
for (int j = 0; j < 25; j++)
{
if (j == 4)
goto exitLoop;
//...
}
}

exitLoop:
//cleanup
return;

As long as the exitLoop label is immediately after the loop there is little chance that anything goes wrong here thus I think it is quite okay to use goto this way but you can also use a bool variable to achieve the same.

bool breakAll;
for (int i = 0; i < 25; i++)
{
for (int j = 0; j < 25; j++)
{
if (j == 4)
{
breakAll = true;
break;
}
//...
}
if (breakAll)
break;
}

The later has the disadvantage that you have to remember to check for the breakAll variable in every loop. A better option in my opinion is to refactor the nested loops into a single method where you can use the return statement in order to break out of them.

So, when do you use goto’s?

I didn’t have to use a single goto statement in production code myself but I can see some situations where it might be efficient to use one. I guess the reason why I am not using it is because most of the time there is a better or equal alternative and I am one of these developers who enjoys refactoring/improving code which means that if I have to chose between ‘refactor the program flow’ or ‘use this one little goto statement’ it is highly likely that I will do the former. (and that has nothing to do with my fear of raptors)