Saturday, October 1, 2011

Class Inheritance and Interface Inheritance

It's also important to understand the difference between class inheritance and interface inheritance (or subtyping). Class inheritance defines an object's implementation in terms of another object's implementation. In short, it's a mechanism for code and representation sharing. In contrast, interface inheritance(or subtyping) describes when an object can be used in place of another.

It's easy to confuse these two concepts, because many languages don't make the distinction explicit. In languages like C++ and Eiffel, inheritance means both interface and implementation inheritance. The standard way to inherit an interface in C++ is to inherit publicly from a class that has (pure) virtual member functions.

Pure interface inheritance can be approximated in C++ by inheriting publicly from pure abstract classes. Pure implementation or class inheritance can be approximated with private inheritance. In Smalltalk, inheritance means just implementation inheritance. You can assign instances of any class to a variable as long as those instances support the operation performed on the value of the variable.

Although most programming languages don't support the distinction between interface and implementation inheritance, people make the distinction in practice. Smalltalk programmers usually act as if subclasses were subtypes (though there are some well-known exceptions [Coo92]); C++ programmers manipulate object through types defined by abstract classes.

Thursday, September 29, 2011

How to change instance name of sql-server

SQL Server doesn’t use the network name, it only excepts that as an alias. My SQL Server instance was still named “old_name”. I found that out by running these two queries:

1

2

sp_helpserver

select @@servername

So in order to get the network name and the SQL Server instance name back in sync I had do these steps:

1. Run this in Microsoft SQL Server Management Studio:

1

2

3

4

sp_dropserver 'old_name'

go

sp_addserver 'new_name','local'

go

2. Restart SQL Server service. I prefer the command prompt for this, but you can just as easily do it in Services under the Control Panel
net stop mssqlserver
net start mssqlserver

Then after that is done run this again, to make sure everything is changed:

1

2

sp_helpserver

select @@servername

For further detail click here

Sunday, September 25, 2011

Unable to connect to mysql host

I was facing a problem, from few days i.e. whenever I tried to connect to Mysql database a message appears, Unable to connect to mysql host. I was using mysql connector for dot net. My connection string was also correct, according to connection-strings site. I had also added Mysql port (3306) in windows firewall, but still the problem persist.

After doing some RND, I saw a post in which it was highlighted that this issue, may be appeared because of Winsock2 corruption. To repair Winsock I used netsh winsock reset command at the command prompt, and then press ENTER. After restarting my notebook, mysql connection starts working.

For detail click here. Thank You.

Friday, September 23, 2011

Classes and Structs in C#

Introduction

There are two main concrete ways of encapsulating data and behavior in the common type system of the .NET Framework: classes and structs. Each one offers benefits over the other, and in this article I am going to briefly introduce these two concepts and discuss how to use each and when to use each based on their differences.

Each of these defines a schema for an object that we can create encapsulating the data and behavior that we want into these objects that we can create at runtime. We are able to create these objects and use them in our code freely at runtime. We can sometimes change the values, use them, pass them around. In object oriented programming, classes and structs are an integral piece of the programming paradigm.

Classes

Classes are the most commonly used of these two forms of encapsulation. The main difference between the two is that classes are a reference type, which means that by default they're used by reference instead of by value.

Structs

Structs are the lesser used of these two forms of encapsulation. The primary distinction of structs is that a struct is a value type, which means that it is stored on the stack instead of the heap and it is passed by value instead of by reference by default.

Structs are behave similarly to the other value types that we see when writing .NET code. These include: integers, doubles, bools, and other value type objects.

Structs don't require constructors, but if there is one, they require that there are parameters in the constructor.

Structs do not require the use of the new keyword in creation, but if you use this syntax you need to initialize the members manually.

Structs do not have access to inheritance.

When to Use Each

Classes are generally used for complex data with lots of behavior as well as for objects which may become large. One major reason for this is that classes never need to be copied when passing them around this means that the same object gets reused and we don't have to be concerned with duplicating such a large object.

Structs are generally used in situations where we need light, quick objects which are not often changed and are used in context. They are less often used when there will be a large amount of behavior associated with the objects.

One great benefit of structs is the avoidance of allocating to the heap and thus the overhead of garbage collection is avoided, but be mindful of doing this with large objects as passing them to methods will require copying them since they are value types.

Passing data to and from programs running in c or c++ is one instance where structs are used instead of classes. These are the objects able to do this work for us.


For detail click here

Earn Money ! Affiliate Program
Open Directory Project at dmoz.org