C# Interfaces- Why We Use Interface

April 1, 2012 at 8:06 PMMehedi Hasan

Interfaces in C # provide a way to achieve runtime polymorphism. Using interfaces we can invoke functions from different classes through the same Interface reference, whereas using virtual functions we can invoke functions from different classes in the same inheritance hierarchy through the same reference. Before things start getting difficult let me start using simple and short examples to explain the concept of interfaces.

Why We use Interface

So if an interface implements no functionality then why should we use them?Using interface based design concept provides loose coupling, component-based programming, easier maintainability, makes your code base more scalable and makes code reuse much more accessible because implementation is separated from the interface. Interfaces add a plug and play like architecture into your applications. Interfaces help define a contract (agreement or blueprint, however you chose to define it), between your application and other objects. This indicates what sort of methods, properties and events are exposed by an object.


For example let's take a vehicle. All vehicles have similar items, but are different enough that we could design an interface that holds all the common items of a vehicle. Some vehicles have 2 wheels, some have 4 wheels and can even have 1 wheel, though these are differences they have something in common, they're all movable, they all have some sort of engine, they all have doors, but each of these items may vary. So we can create an interface of a vehicle that has these properties, then we inherit from that interface to implement it.

While wheels, doors and engines are different they all rely on the same interface (I sure hope this is making sense). Interfaces allow us to create nice layouts for what a class is going to implement. Because of the guarantee the interface gives us, when many components use the same interface it allows us to easily interchange one component for another which is using the same interface. Dynamic programs begin to form easily from this. An interface is a contract that defines the signature of some piece of functionality.

So here's a simple example of an interface and implementing it. From the above example we're created a IVehicle interface that looks like this

namespace InterfaceExample
{
    public interface IVehicle
    {
        int Doors { get; set; }
        int Wheels { get; set; }
        Color VehicleColor { get; set; }
        int TopSpeed { get; set; }
        int Cylinders { get; set; }
        int CurrentSpeed { get; }
 
        string DisplayTopSpeed();
        void Accelerate(int step);
    }
}

Now we have our vehicle blueprint, and all classes that implement it must implement the items in our interface, whether it be a motorcycle, car, or truck class we know that all will contain the same functionality. Now for a sample implementation, in this example we'll create a motorcycle class that implements our IVehicle class. This class will contains everything we have defined in our interface,

namespace InterfaceExample
{
    public class Motorcycle : IVehicle
    {
        private int _currentSpeed = 0;

        public int Doors { get; set; }

        public int Wheels { get; set; }

        public Color VehicleColor { get; set; }

        public int TopSpeed { get; set; }

        public int HorsePower { get; set; }

        public int Cylinders { get; set; }

        public int CurrentSpeed
        {
            get { return _currentSpeed; }
        }


        public Motorcycle(int doors, int wheels, Color color, int topSpeed, int horsePower, int cylinders, int currentSpeed)
        {
            this.Doors = doors;
            this.Wheels = wheels;
            this.VehicleColor = color;
            this.TopSpeed = topSpeed;
            this.HorsePower = horsePower;
            this.Cylinders = cylinders;
            this._currentSpeed = currentSpeed;
        }

        public string DisplayTopSpeed()
        {
            return "Top speed is: " + this.TopSpeed;
        }

        public void Accelerate(int step)
        {
            this._currentSpeed += step;
        }
    }
}

Now in the same application we could interchange our Motorcycle class with a Truck class or a Car class and they will all have the same base functionality, that of a IVehicle.

So as you can see interface based development can make a developers life much easier, and our applications much cleaner, maintainable and extensible.




Article Source : http://dotnet.dzone.com/articles/c-interfaces-what-are-they-and

Posted in: C Sharp

Tags:

Fade out the bottom of the page using CSS

January 17, 2012 at 3:40 AMMeherunnessa Mitu

CSS can be used to fade out the bottom of the page just creating a fixed-position div with a transparent image and using z-index property with high value. The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order.

Here is the CSS code for fade out bottom -
body
{
    font-family: "Lucida Grande", Georgia, sans-serif;
    font-size: 15px;
}

p
{
    font-size: 14px;
    line-height: 1.5em;
}

#page_wrap
{
    width: 600px;
    z-index: 1;
    margin: 2px auto;
}

#bottom_fade
{
    width: 600px;
    height: 180px;
     z-index: 120;
     position: fixed;
    bottom: 0px;
    background: url('images/bottom-fade.png') bottom center no-repeat;   
}

Put the reference of your style sheet, then create two divs as shown below -
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Fade out bottom of the page using CSS</title>
    <link href="App_Themes/Theme1/FadeOutBottom.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div id="textdiv">
    <h1>Fade out bottom</h1><br />
    <p>
    Completely revolutionize high-quality niches after mission-critical expertise. Professionally deploy standardized total linkage before interoperable architectures. Quickly formulate future-proof meta-services through cross functional portals. Holisticly procrastinate timely results vis-a-vis principle-centered human capital. Distinctively incubate emerging systems and collaborative best practices. Compellingly exploit next-generation technology via web-enabled results.<br />

Professionally disintermediate 24/365 web services via intermandated technologies. Holisticly disseminate flexible web services through professional results. Enthusiastically empower integrated channels and standards compliant channels. Proactively brand end-to-end process improvements rather than resource sucking results. <br />

Credibly aggregate dynamic synergy and one-to-one testing procedures. Credibly synergize out-of-the-box growth strategies via timely mindshare. Synergistically embrace extensive schemas and multidisciplinary processes. Monotonectally synergize 2.0 sources before resource-leveling sources. Professionally grow value-added results before client-based internal or "organic" sources. <br />

Quickly fabricate out-of-the-box relationships via top-line e-services. Uniquely restore market positioning synergy rather than long-term high-impact manufactured products. Monotonectally plagiarize high-payoff interfaces rather than business internal or "organic" sources. Credibly synergize plug-and-play interfaces rather than intuitive results. Compellingly expedite fully tested outsourcing vis-a-vis impactful synergy. <br />


Distinctively re-engineer impactful architectures and resource sucking niches. Authoritatively envisioneer leveraged total linkage whereas vertical value. Phosfluorescently iterate dynamic opportunities through multimedia based systems. Uniquely e-enable frictionless paradigms after B2C initiatives. Credibly deliver go forward methods of empowerment via professional total linkage. Dramatically deliver client-based portals whereas collaborative innovation. <br />
    </p>
    <div id="bottom_fade">
    </div>
    </div>
    </form>
</body>
</html>

That's it.

Source: http://css-tricks.com/examples/FadeOutBottom

Posted in: CSS

Tags: ,

How to create a form without using tables

January 11, 2012 at 2:17 AMMeherunnessa Mitu

I think it's better idea to avoid tables to create forms, because it increases lines of code. Whereas use of css reduces the lines of code by containing the visual information into it. There are lots of reasons to choose css instead of table. Before I show you the procedure, you should read the article 'CSS vs Tables' to know more about the advantages of using CSS to create forms rather than table.

Let's do it. First create a style sheet and write the following code into it -

body
{
font-family:"Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}

p, h1, form, button
{
    border:0; margin:0; padding:0;
}

#wrapdiv
{
margin:0 auto;
width:400px;
padding:14px;
}

#maindiv
{
border:solid 2px #b7ddf2;
background:#ebf4fb;
}

#h1
{
font-size:14px;
font-weight:bold;
margin-bottom:8px;
}

#p
{
font-size:11px;
color:#666666;
margin-bottom:20px;
border-bottom:solid 1px #b7ddf2;
padding-bottom:10px;
}

.label
{
display: block;
font-weight:bold;
text-align: right;
width:140px;
float:left;
}

.textbox
{
float:left;
font-size:12px;
padding:4px 2px;
border:solid 1px #aacfe4;
width:200px;
margin:2px 0 20px 10px;
}

.checkbox
{
  float: left;
  padding-left: 2px;
  font-weight: bold;
  margin: 2px 0 10px 6px;
}

.button
{
clear:both;
margin-left:150px;
width:125px;
height:31px;
background-color:#666666;
text-align:center;
line-height:31px;
color:#FFFFFF;
font-size:11px;
font-weight:bold;
}

After that create a web form and just write the code as given below -

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Creating a layout form only using CSS</title>
    <link href="DesignLayoutForm.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
  <div id="wrapdiv">
      <div id="maindiv">
            <h1>
                A simple form</h1>
            <br />
    <asp:Label ID="lblFirstName" runat="server" Text="First Name" CssClass="label"></asp:Label>
    <asp:TextBox ID="txtFirstName" runat="server" CssClass="textbox"></asp:TextBox>
    <asp:Label ID="lblLastName" runat="server" Text="Last Name" CssClass="label"></asp:Label>
    <asp:TextBox ID="txtLastName" runat="server" CssClass="textbox" ToolTip="enter last name"></asp:TextBox>
    <asp:Label ID="lblGender" runat="server" CssClass="label" Text="Gender"></asp:Label>
    <asp:CheckBox ID="CheckBox1" runat="server" CssClass="checkbox" Text="Male" />
    <asp:CheckBox ID="CheckBox2" runat="server" CssClass="checkbox" Text="Female"/>
    <asp:Label ID="lblAddress" runat="server" CssClass="label" Text="Address"></asp:Label>
    <asp:TextBox ID="txtAddress" runat="server" CssClass="textbox" TextMode="MultiLine"></asp:TextBox>
    <asp:Label ID="lblEmailAddress" runat="server" Text="Email Address" CssClass="label"></asp:Label>
    <asp:TextBox ID="txtEmailAddress" runat="server" CssClass="textbox"></asp:TextBox>
    <asp:Label ID="lblPassword" runat="server" Text="Password" CssClass="label"></asp:Label>
    <asp:TextBox ID="txtPassword" runat="server" CssClass="textbox" TextMode="Password"></asp:TextBox>
    <asp:Label ID="lblConfirmPassword" runat="server" Text="Confirm Password" CssClass="label"></asp:Label>
    <asp:TextBox ID="txtConfirmPassword" runat="server" CssClass="textbox" TextMode="Password"></asp:TextBox>           
    <asp:Button ID="btnSubmit" CssClass="button" runat="server" Text="Submit" />
  <br />
  <br />           
      </div>
  </div>
</form>
</body>
</html>

Here I don't need to use any table, all you need to do is just use 'CssClass' property. The CssClass property enables you to assign a style sheet class to the specific control. In this code I use Cssclass for label, textbox, checkbox and button control. Css code creates the layout of the form. Run the page, you will see a simple form with some fields.

Do you have some better idea to create form???

Posted in: ASP.NET | CSS

Tags: , ,

How to give blink effect to a message box using jQuery

January 6, 2012 at 5:09 PMMeherunnessa Mitu

In my preious article How to create message boxes for different types of message using CSS I show you how to create message boxes for different message types. Now I want to show you how to animate message boxes which is being shown and drive it away after you read it. Here is the procedure - 

Add the given css code in the style sheet so that it looks cool...

#info
{
    font-family: Verdana, sans-serif;
    font-size:13px;
    border: 1px solid;
    margin: 10px 0px;
    padding:15px 10px 15px 50px;
    background-repeat: no-repeat;
    background-position: 10px center;
    position:relative;
    color: #00529B;
    background-color: #BDE5F8;
    background-image: url('images/info.png');
}

The following code allows message box to blink to let you know that you should read it -

       $(document).ready(function () {
            $(".close").click(function () {
                $("#info").animate({ left: "+=20px" }).animate({ left: "-3000px" });
            });
            $("#info").fadeOut(800).fadeIn(800).fadeOut(400)
            .fadeIn(400).fadeOut(400).fadeIn(400);      

          });

Here is the complete code with above one -

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Animate message boxes with jQuery</title>
    <link href="App_Themes/Theme1/AnimateMsgBox.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
    </script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $(".close").click(function () {
                $("#info").animate({ left: "+=20px" }).animate({ left: "-3000px" });
            });
            $("#info").fadeOut(800).fadeIn(800).fadeOut(400)
            .fadeIn(400).fadeOut(400).fadeIn(400);
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="info">
    script.aculo.us is a set of JavaScript libraries to enhance the user interface of web sites. It provides an visual effects engine, a drag and drop library, a couple of controls and more.
    <a href="#" class="close">click to go away!!!</a>
    </div>
    </form>
</body>
</html>

Now see the effect in browser you have just made.

Posted in: jQuery

Tags: ,

Get the location of stored ASP.NET temporary files

January 5, 2012 at 12:21 AMMeherunnessa Mitu

Do you know that where are the temporary files of ASP.NET stored? It's easy to find out. ASP.NET provides a property called 'HttpRuntime.CodegenDir' whose task is to get the physical path to the directory where ASP.NET stores temporary files (generated sources, compiled assemblies, and so on) for the current application. So, using this property you can find out the location of ASP.NET temporary files.

Here's the code to get the location of stored ASP.NET temporary files -

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(HttpRuntime.CodegenDir);
    }
}

After running this I get the following output for my machine,

C:\Users\Mitu\AppData\Local\Temp\Temporary ASP.NET Files\website10\58b51661\f65bc1a6

Hope it works for you!!

Smile

Posted in:

Tags:

How to create message boxes for different types of message using CSS

January 4, 2012 at 8:50 PMMeherunnessa Mitu

Today I want to share a CSS code to create some message boxes which contains different messages. Let's see how to do it.

Create a style sheet and put the following code into style sheet -

body
{
font-family: Verdana, sans-serif;
font-size:13px;
}

.info, .success, .warning, .error
{
border: 1px solid;
margin: 10px 0px;
padding:15px 10px 15px 50px;
background-repeat: no-repeat;
background-position: 10px center;
}

.info
{
color: #00529B;
background-color: #BDE5F8;
background-image: url('images/info.png');
}

.success
{
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('images/success.png');
}

.warning
{
color: #9F6000;
background-color: #FEEFB3;
background-image: url('images/warning.png');
}

.error
{
color: #D8000C;
background-color: #FFBABA;
background-image: url('images/error.png');
}

Make sure that image url used in the style sheet is correct, otherwise images will not be displayed. Then give the reference of style sheet into the head tag and create four divs containing some information as shown below -

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Creating message boxes using CSS</title>
    <link href="App_Themes/Theme1/MessageBoxUsingCss.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div class="info">
    These topics will help you get started with Windows 7. You can also go to the Windows website to learn more.
    </div>

    <div class="success">Your information have been saved successfully.</div>
   
    <div class="warning">Your profile has been saved successfully, but confirmation mail could not be sent to the email address you provided.</div>

    <div class="error">All of your game progress will be lost.</div>
    </form>
</body>
</html>

That's it. Run the page and you will see four message boxes for four different message types.

Posted in: CSS

Tags:

How to print only Text using Media attribute

December 31, 2011 at 5:45 PMMeherunnessa Mitu

When you create a web page you usually keep in mind how it will rendered on the browser and its usability. Sometime, depending upon the content, you also know that your page might be printed by end user. But you don’t want that the printer version of your page to be same as it shown on browser. This problem can be solved using media attribute. By using this you can specify on which media a particular style sheet will be applicable. So you can have different style sheet for printer and browser screen and user don’t have to worry about this.

As web page contains text with different things like images, links, menus etc. Suppose you don't need the images in the printer view. So let's remove it. All you need to do is just create a style sheet and put the following code -

img
{
    display: none;
}

Then put the reference of style sheet in aspx page and add media attribute with value print in to the 'link' tag. 'print'  which means the style sheet will only be applied when you print the document. You can use this to hide images when you print. Here's the code -

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Print only text using CSS</title>
    <link href="App_Themes/Theme1/print.css" rel="stylesheet" media="print" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <img src="Images/logo.jpg" alt="Google" />
    <p>Founders Larry Page and Sergey Brin named the search engine they built “Google,” a play on the
    word “googol,” the mathematical term for a 1 followed by 100 zeros. The name reflects the immense
    volume of information that exists, and the scope of Google’s mission: to organize the world’s
    information and make it universally accessible and useful.
    </p>
    </div>
    </form>
</body>
</html>

The above code is a small HTML page which displays Google’s logo and some sample text. When you print this, the image won’t be displayed.

Posted in: CSS

Tags: , ,

Refresh or reload a page using jQuery

December 26, 2011 at 2:21 AMMeherunnessa Mitu

jQuery can be used to refresh or reload a web page. Put the code in the source view of your aspx page and then view it in a browser.

Following is the code for reloading a page using jQuery -

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Reload/Refresh a Page in jQuery</title>
    <script type="text/javascript"
        src="http://code.jquery.com/jquery-latest.js">
    </script>
 
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnReload').click(function () {
                location.reload();
            });
        });    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnReload" runat="server" Text="Button" />   
    </div>
    </form>
</body>
</html>


Posted in: jQuery

Tags: ,

How to create Triangles using plain CSS

December 25, 2011 at 1:07 AMMeherunnessa Mitu

Today i am sharing a trick to create triangles using plain CSS. Let me show you how to achieve traingle using CSS.

First in your stylesheet write down the following CSS code -

#one
{
    height: 0;
    width: 0;
    border-top: 90px solid #C1B2B3;
    border-left: 90px solid #DDD3EA;
    border-right: 90px solid #C6CDD6;
    border-bottom: 90px solid #D1E7BC;
    margin: 20px;
}

Then link the stylesheet in your aspx page and give the name of div id ="one" as shown below -

<head runat="server">
    <title>Create triangle using plain CSS without using no images</title>
    <link href="StyleSheetForTriangle.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div id="one">   
    </div>
    </form>
</body>
</html>
 

After that run the aspx page.


Posted in: CSS

Tags: ,

Terms in ADO.NET

December 10, 2011 at 12:09 AMMeherunnessa Mitu

ADO.NET(ActiveX Data Object.NET for .net) is a software library in the .NET framework consisting of software components providing data access services. ADO.NET provides a rich set of components for creating distributed, data-sharing applications. It is an integral part of the .NET Framework, providing access to relational, XML, and application data. ADO.NET separates data access from data manipulation into discrete components that can be used separately.

Terms used in ADO.NET -

  • Data Source: It can be a database, text file, excel spread sheet or an XML file.
  • Data Provider: A set of libraries that is used to communicate with data source. For exp - SQL data provider for SQL, OLE DB data provider for access, excel etc.
  • SQL Connection: It establishes connection.
  • SQL Command: It allows to manipulate database by executing stored procedure or sql statements.
  • SQL DataReader: This retrieves data in forward only and read-only form.
  • DataSet: Dataset is a disconnected, in memory representation of data. It can contain multiple data table from different database.
  • SQL DataAdapter: It populates dataset from data source. It contains a reference to the connection object and opens and closes the connection automatically when reading from or writing to the database.
  • DataView: It provides a means to filter and sort data within a data table.
  • Disconnected Data Source: Ado.net makes the connection to the database server only when it needs to do a transaction and disconnects once the transaction is over (similar to an http connection over the internet).
  • Strongly Typed Dataset Object: Strongly typed Dataset object allows you to create early-bound data retrieval expression. It is faster than late-bound data retrieval expression.



Posted in: C Sharp | ASP.NET | C Sharp

Tags: , , , ,