Hunt

Thursday, January 19, 2012

PROGRAMMING TIPS

Object-oriented programming Concepts
Class

A class is a template for an object, a user-defined datatype that contains variables, properties, and methods. A class defines the abstract characteristics of a thing (object), including its characteristics (its attributes, fields or properties) and the things it can do (behaviors, methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.

Instance

One can have an instance of a class; the instance is the actual object created at run-time. In programmer vernacular, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behavior that's defined in the object's classes.

Method

Method is a set of procedural statements for achieving the desired result. It performs different kinds of operations on different data types. In a programming language, methods (sometimes referred to as "functions") are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat() or walk() or save(Timmy). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking.


Message passing

"The process by which an object sends data to another object or asks the other object to invoke a method."[13] Also known to some programming languages as interfacing. For example, the object called Breeder may tell the Lassie object to sit by passing a "sit" message that invokes Lassie's "sit" method. The syntax varies between languages, for example: [Lassie sit] in Objective-C. In Java, code-level message passing corresponds to "method calling". Some dynamic languages use double-dispatch or multi-dispatch to find and pass messages. Method is a block of code which we call multiple times,supports re-useability []([]) { statement; }


Abstraction

Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes.
Abstraction is a mechanism where we hide the implementation or another way of looking , we want to achieve loose coupling.

Encapsulation

Encapsulation conceals the functional details of a class from objects that send messages to it.

For example, the Dog class has a bark() method variable, data. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in the future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET). Eiffel and C++ allow one to specify which classes may access any member.

Inheritance

Inheritance allows the programmer to treat derived class members just like their parent class's members. This type of relationship is called child-Parent or is-a relationship. "Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.

For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.

Each subclass can alter its inherited traits. For example, the Collie subclass might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an "a… is a" relationship between classes, while instantiation is an "is a" relationship between an object and a class: a Collie is a Dog ("a… is a"), but Lassie is a Collie ("is a"). Thus, the object named Lassie has the methods from both classes Collie and Dog.

Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two that inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard to implement.

polymorphism

Polymorphism is a process in which a class has all the state and behavior of another class.

More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). Each subclass overrides the speak() method inherited from the parent class Animal.

Decoupling

Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically decouple the encapsulation,[clarification needed] which is the practice of using reusable code to prevent discrete code modules from interacting with each other. However, in practice decoupling often involves trade-offs with regard to which patterns of change to favor. The science of measuring these trade-offs in respect to actual change in an objective way is still in its infancy.[citation needed]

---------------------------------------------------------------
AllowDefinition MachineToApplication Beyond Application Level Error ?
Hi to All,

Recently i faced this issue in my application .

This error can be caused by a virtual directory not being configured as an application in IIS.

This error is caused mainly for two reasons.



1. Virtual directory not configured in IIS.


If you have not Configured your application to run on IIS then Create a virtual directory and assign permissions to Application (Read,Write).

Open IIS manager by typing INETMGR by clicking start menu > Run on windows

This will open IIS manager, now right click on the folder containing ur web application files and select properties.

In directory tab click on create button associated with Application name section.


Click on apply and this should fix the problem.


2. Two or more web.config files.


Chekc whether u r having two or more web.config files in ur application ?

If yes than remove one, web.config file should be in root under virtual directory.

Remove any backup folders if you have which may contain web.config file.
-------------------------------------------------------


Index Optimization tips
• Every index increases the time in takes to perform INSERTS, UPDATES and DELETES, so the number of indexes should not be very much. Try to use maximum 4-5 indexes on one table, not more. If you have read-only table, then the number of indexes may be increased.
• Keep your indexes as narrow as possible. This reduces the size of the index and reduces the number of reads required to read the index.
• Try to create indexes on columns that have integer values rather than character values.
• If you create a composite (multi-column) index, the order of the columns in the key are very important. Try to order the columns in the key as to enhance selectivity, with the most selective columns to the leftmost of the key.
• If you want to join several tables, try to create surrogate integer keys for this purpose and create indexes on their columns.
• Create surrogate integer primary key (identity for example) if your table will not have many insert operations.
• Clustered indexes are more preferable than nonclustered, if you need to select by a range of values or you need to sort results set with GROUP BY or ORDER BY.
• If your application will be performing the same query over and over on the same table, consider creating a covering index on the table.
• You can use the SQL Server Profiler Create Trace Wizard with "Identify Scans of Large Tables" trace to determine which tables in your database may need indexes. This trace will show which tables are being scanned by queries instead of using an index.
• You can use sp_MSforeachtable undocumented stored procedure to rebuild all indexes in your database. Try to schedule it to execute during CPU idle time and slow production periods.
sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?')"


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

5 Ways to Improve Your Website
1. Site Search

When you have more than 20 pages, it's a good idea to add a search facility. If you have a site search, make sure it's prominent. Usability guidelines tend to prefer the upper-right corner of the page. Keep the button label simple and clear - "Search" still works best for most sites. Don't unleash your powers of lateral thinking and swap in a word like "Retrieve". Keep it simple.

To Do: Just using your search, try to find 3 pages of content. Is that process "quick, easy and straight-forward?" Or is it "hit and miss?"


2. Ensure Your Webpages Can Be Skim-read Easily

Few people read word for word online; the vast majority skim-read to get a sense of the page before they read any of it in detail. Make it easy for visitors to skim-read your content. Always use headings and bullets to break up text.

Think about it. If a heading is not relevant for your visitor, they can easily skim down to the next heading, making it straightforward for them to get directly to the information they need.

To Do: Give your website a quick review and make sure all your text is broken up into clear, manageable sections.


3. Keep Your Styles & Colors Consistent

Make sure people know they're still on your site by being consistent - confuse them and you'll lose them. Keep the look and feel of your website sections consistent and avoid any radical changes. Visitors can get confused and think they have left your site accidentally.

Layout, headings, and styles should be consistent site-wide, and colors should usually have the same meaning.

For example, don't use red for headers on one page, red for hyperlinks on another, and red as standard text somewhere else.

To Do: Ensure all your web pages appear to be part of the main site and that they are consistent with each other. Are there any "nasty surprises" depending on the part of the site you're in?

4. Use Emphasis (bold, etc.) Sparingly

It's a fact of human psychology: try to draw attention to everything and you'll effectively draw attention to nothing. We've all seen that site, the one with a red, blinking, underlined "NEW!" next to everything. Don't be that guy or gal.

Remember, if your site's graphic design is counter-intuitive and doesn't help visitors get something done quickly, it's going to make your site much slower and difficult to work with.

Slow, awkward sites don't ever, ever, delight your customer or create a good rapport online.

Visitors will be back at the search engine in seconds if they find your website "complicated" or "busy".

To Do: Ensure your website is only highlighting critical factors you absolutely need your visitors to gaze at or click on in order to meet your online business goals. Menus, buy buttons, opt–in boxes and so on.


5. Keep Your Ads & Pop-ups Unobtrusive

Ads are a fact of life, but integrate them nicely into your site. Don't try to force ads and pop-ups down peoples' throats; you'll end up creating frustration for your visitors. Also, do people a favor and make your ads clear. If you blur the line between ads and content too much, your content may suffer, since many people have developed "banner blindness" when it comes to surfing, and might overlook some important content by mistake.

To Do: Doublecheck if your pop-up window is significantly increasing your opt–in rate. If it isn't, you could be annoying present and future customers unnecessarily.

Final Word

Always make sure you view your website through the eyes of the customer and not through your eyes, the website owner.

Make sure there are no red-flags on your site that are going to frustrate, confuse or bore customers. Keep everything nice and simple to make sure your visitors enjoy spending time (and money) on your site

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

Common Events of HTML Objects

onChange:--> Occurs when the user changes value in an input control. In text controls, this event fires after the user changes focus to another control.
Applies To: select, text, text area

onClick:--> Occurs when the user clicks a control.
Applies To: button, check box,radio, link, area

onMouseOver:--> Occurs when the user moves the mouse pointer over a control.
Applies To: link, area

onMouseOut:--> Occurs when the user moves the mouse pointer away from a control.
Applies To: link, area

onKeyUp:--> Occurs when the user presses a key.
Applies To: text, text area

onKeyDown:--> Occurs when the user releases a pressed key.
Applies To: text, text area

onSelect:--> Occurs when the user selects a portion of text in an input control.
Applies To: text, text area

onFocus:--> Occurs when a control receives focus.
Applies To: select, text, text area

onBlur:--> Occurs when focus leaves a control.
Applies To: select, text, text area

onAbort:--> Occurs when the user cancels an image download.
Applies To: image

onError:--> Occurs when an image can’t be downloaded
(probably because of an incorrect URL).
Applies To: image

onLoad:--> Occurs when a new page finishes downloading.
Applies To: window, location

onUnload:--> Occurs when a page is unloaded. (This typically occurs after a new URL has been entered or a link has been clicked. It fires just before the new page is downloaded.)
Applies To: window

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

No comments:

Post a Comment