1. What is architecture of your project ?
2. Why use interface (its advantage) when business logic layer can use ?
ANS -
First and foremost, interfaces in C# are a means to get around the lack of multiple inheritance in C#, meaning you cannot inherit from multiple classes but you can implement multiple interfaces.
An interface is a contract between itself and any class that implements it. This contract states that any class that implements the interface will implement the interface's properties, methods and/or events.
Why use interfaces
1. 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.
There are several other reasons why you might want to use interfaces instead of class inheritance:
- Interfaces are better suited to situations in which your applications require many possibly unrelated object types to provide certain functionality.
- Interfaces are more flexible than base classes because you can define a single implementation that can implement multiple interfaces.
- Interfaces are better in situations in which you do not have to inherit implementation from a base class.
Example of an interface and implementing it. From the above example we're created a IVehicle interface that looks like this
01.namespace InterfaceExample02.{03.public interface IVehicle04.{05.int Doors { get; set; }06.int Wheels { get; set; }07.Color VehicleColor { get; set; }08.int TopSpeed { get; set; }09.int Cylinders { get; set; }10.int CurrentSpeed { get; }11. 12.string DisplayTopSpeed();13.void Accelerate(int step);14.}15.}01.namespace InterfaceExample02.{03.public class Motorcycle : IVehicle04.{05.private int _currentSpeed = 0;06. 07.public int Doors { get; set; }08. 09.public int Wheels { get; set; }10. 11.public Color VehicleColor { get; set; }12. 13.public int TopSpeed { get; set; }14. 15.public int HorsePower { get; set; }16. 17.public int Cylinders { get; set; }18. 19.public int CurrentSpeed20.{21.get { return _currentSpeed; }22.}23. 24. 25.public Motorcycle(int doors, int wheels, Color color, int topSpeed,int horsePower, int cylinders, int currentSpeed)26.{27.this.Doors = doors;28.this.Wheels = wheels;29.this.VehicleColor = color;30.this.TopSpeed = topSpeed;31.this.HorsePower = horsePower;32.this.Cylinders = cylinders;33.this._currentSpeed = currentSpeed;34.}35. 36.public string DisplayTopSpeed()37.{38.return "Top speed is: " + this.TopSpeed;39.}40. 41.public void Accelerate(int step)42.{43.this._currentSpeed += step;44.}45.}So as you can see interface based development can make a developers life much easier, and our applications much cleaner, maintainable and extensible.
_______________________________________________________________________________
2 .How you doing commit in DAL write code..?
(B)
----------------------------------------------------------------------------------------------------------------------------------
3. Advantage of precedure then inline SQL statement, which is faster and why?
ANS .
Stored Procedures are precompiled so they are faster
Ask any one why he prefers stored procedures as compared to inline queries and most will reply back with a standard statement:
“Stored procedures are precompiled and cached so the performance is much better.”
Let me just explain the above sentence more diagrammatically. When we fire SQL for the first time, three things happen:
- The SQL syntax is checked for any errors.
- The best plan is selected to execute the SQL (choice to use clustered index, non-clustered etc.).
- Finally the SQL is executed.
The above statement states that when you run a stored procedure for the first time it will go through all the above steps and the plan will be cached in-memory. So the next time when the stored procedure is executed it just takes the plan from the cache and executes the same. This increases performance as the first two steps are completely eliminated.
The above statement also says / implies that for inline queries all the above steps are repeated again and again which brings down the performance considerably.
The above explanation was pretty valid and true for older versions of SQL Server, but from 2005 onwards, all SQL statements, irrespective of it’s a SQL coming from inline code or stored procedure or from anywhere else, they are compiled and cached.
Other banifit -
Abstraction
By putting all your SQL code into a stored procedure, your application is completely abstracted from the field names, tables names, etc. So when you make changes in the SQL, you have less impact in your C# code.
Security
This is the best part where stored procedures again score, you can assign execution rights on users and roles.
Maintenance ease
Now because we have centralized our stored procedures any issue like fixing defects and other changes can be easily done in a stored procedure and it will be reflected across the installed clients. At least we do not need to compile and deploy DLLs and EXEs.
Centralized tuning
If we know we have a slow running stored procedure, we can isolate it and the DBA guys can performance tune it separately.
------------------------------------------------------------------------------------------------------------
4. Dataset and data reader difference how dataset disconnected which is faster and why ?which one you use in project..?.
Disadvantage -
One possible disadvantage of using a DataReader is that the connection must be open while you are accessing the data. If you will be doing lengthy processing with each row of returned data, a DataSet might be a better idea.
The DataSet, however, doesn't need to know about where it gets its data. The DataReader can only get its data from a data source through a managed provider. The DataSet can also get its data from a data source via a managed provider, but the data source can also be loaded manually, even from an XML file on a hard drive. If the .NET Framework does not provide a managed provider that is specifically designed for your database, it is certainly worth checking to see if the manufacturer or a third party has one available since they should perform better than the generic OLE DB and ODBC providers.
Disadvantage -
The dark side of using DataSets is that the data remains in memory for as long as you use it. If you are retrieving thousands or millions of rows, a DataSet is probably not an ideal solution.
----------------------------------------------------------------------------------------------------------------------------------
5. what exteded method you using (which
comes in intelisenec).
Using extension methods, you can use your new methods as a part of
int class in .NET.
In the above screen shot, I wrote the following line of code:
int x = 3;
x.factorial();
Factorial method becomes a part of
int class by implementing factorial method as an extension method in my class without inheriting int class in .NET, see below (Figure 1.1). What’s the Specification of an Extension Method?
An extension method is a special kind of
static method that allows you to add new methods to existing types without creating derived types.
The extension methods are called as if they were instance methods from the extended type, For example:
x is an object from int class and we called it as an instance method in int class.How to Create my Extension Method?
Simply, you create your own
static method in your class and put this keyword in front of the first parameter in this method (the type that will be extended).public static class MyMathExtension
{
public static int factorial(this int x)
{
if (x <= 1) return 1;
if (x == 2) return 2;
else
return x * factorial(x - 1);
}
}



No comments:
Post a Comment