Aman Bindal
+ve Mantra for 2011: Engage in your Dreams, Take Risks and Enjoy the free fall..!!
Thursday, October 16, 2014
Tuesday, March 15, 2011
Abstract Classes vs. Interfaces- With Examples
I am assuming you are having all the basic knowledge of abstract and interface keyword. I am just briefing the basics.
We can not make instance of Abstract Class as well as Interface.
Here are few differences in Abstract class and Interface as per the definition.
Abstract class can contain abstract methods, abstract property as well as other members (just like normal class).
Interface can only contain abstract methods, properties but we don’t need to put abstract and public keyword. All the methods and properties defined in Interface are by default public and abstract.
//Abstarct Class
public abstract class Vehicles
{
private int noOfWheel;
private string color;
public abstract string Engine
{
get;
set;
}
public abstract void Accelerator();
}
//Interface
public interface Vehicles
{
string Engine
{
get;
set;
}
void Accelerator();
}
We can see abstract class contains private members also we can put some methods with implementation also. But in case of interface only methods and properties allowed.
We use abstract class and Interface for the base class in our application.
This is all about the language defination. Now million doller question:
How can we take decision about when we have to use Interface and when Abstract Class.
Basicly abstact class is a abstract view of any realword entity and interface is more abstract one. When we thinking about the entity there are two things one is intention and one is implemntation. Intention means I know about the entity and also may have idea about its state as well as behaviour but don’t know about how its looks or works or may know partially. Implementation means actual state and behaviour of entity.
Enough theory lets take an example.
I am trying to make a Content Management System where content is a genralize form of article, reviews, blogs etc.
CONTENT
ARTICLE
BLOGS
REVIEW
So content is our base class now how we make a decision whether content class should be Abstract class, Interface or normal class.
First normal class vs other type (abstract and interface). If content is not a core entity of my application means as per the business logic if content is nothing in my application only Article, Blogs, Review are the core part of business logic then content class should not be a normal class because I’ll never make instance of that class. So if you will never make instance of base class then Abstract class and Interface are the more appropriate choice.
Second between Interface and Abstract Class.
CONTENT
Publish ()
ARTICLE
BLOGS
REVIEW
As you can see content having behavior named “Publish”. If according to my business logic Publish having some default behavior which apply to all I’ll prefer content class as an Abstract class. If there is no default behavior for the “Publish” and every drive class makes their own implementation then there is no need to implement “Publish” behavior in the base case I’ll prefer Interface.
These are the in general idea of taking decision between abstract class, interface and normal class. But there is one catch. As we all know there is one constant in software that is “CHANGE”. If I made content class as Interface then it is difficult to make changes in base class because if I add new method or property in content interface then I have to implement new method in every drive class. These problems will over come if you are using abstract class for content class and new method is not an abstract type. So we can replace interface with abstract class except multiple inheritance.
CAN-DO and IS-A relationship is also define the deference between Interface and abstract class. As we already discuss Interface can be use for multiple inheritance for example we have another interface named “ICopy” which having behavior copy and every drive class have to implements its own implementation of Copy. If “Article” class drive from abstract class Content as well as ICopy then article “CAN-DO” copy also.
IS-A is for “generalization” and “specialization” means content is a generalize form of Article, Blogs, Review and Article, Blogs, Review are a specialize form of Content.
So, abstract class defines core identity. If we are thinking in term of speed then abstract is fast then interface because interface requires extra in-direction.
So as per my view Abstract class having upper-hand in compare to interface. Using interface having only advantage of multiple inheritance. If you don’t understand the things then don’t worry because it’s my mistake because I am not able to describe the topic.
-------------------
We use abstract class and interface where two or more entities do same type of work but in different ways. Means the way of functioning is not clear while defining abstract class or interface. When functionality of each task is not clear then we define interface. If functionality of some task is clear to us but there exist some functions whose functionality differs object by object then we declare abstract class.
We can not make instance of Abstract Class as well as Interface. They only allow other classes to inherit from them. And abstract functions must be overridden by the implemented classes. Here are some differences in abstract class and interface.
An interface cannot provide code of any method or property, just the signature. we don't need to put abstract and public keyword. All the methods and properties defined in Interface are by default public and abstract. An abstract class can provide complete code of methods but there must exist a method or property without body.
A class can implement several interfaces but can inherit only one abstract class. Means multiple inheritance is possible in .Net through Interfaces.
If we add a new method to an Interface then we have to define implementation for the new method in every implemented class. But If we add a new method to an abstract class then we can provide default implementation and therefore all the existing code might work properly
----
If a class is to serve the purpose of providing common fields and members to all subclasses, we create an Abstract class. For creating an abstract class, we make use of the abstract keyword. Such a class cannot be instantiated. Syntax below:
abstract public class Vehicle { }
Above, an abstract class named Vehicle has been defined. We may use the fields, properties and member functions defined within this abstract class to create child classes like Car, Truck, Bike etc. that inherit the features defined within the abstract class. To prevent directly creating an instance of the class Vehicle, we make use of the abstract keyword. To use the definitions defined in the abstract class, the child class inherits from the abstract class, and then instances of the Child class may be easily created.
Further, we may define abstract methods within an abstract class (analogous to C++ pure virtual functions) when we wish to define a method that does not have any default implementation. Its then in the hands of the descendant class to provide the details of the method. There may be any number of abstract methods in an abstract class. We define an abstract method using the abstract keyword. If we do not use the abstract keyword, and use the virtual keyword instead, we may provide an implementation of the method that can be used by the child class, but this is not an abstract method.
Remember, abstract class can have an abstract method, that does not have any implementation, for which we use the abstract keyword, OR the abstract class may have a virtual method, that can have an implementation, and can be overriden in the child class as well, using the override keyword. Read example below
Example: Abstract Class with Abstract method
namespace Automobiles
{
public abstract class Vehicle
{
public abstract void Speed() //No Implementation here, only definition
}
}
Example: Abstract Class with Virtual method
namespace Automobiles
{
public abstract class Vehicle
{
public virtual void Speed() //Can have an implementation, that may be overriden in child class
{
...
}
}
Public class Car : Vehicle
{
Public override void Speed()
//Here, we override whatever implementation is there in the abstract class
{
... //Child class implementation of the method Speed()
}
}
}
An Interface is a collection of semantically related abstract members. An interface expresses through the members it defines, the behaviors that a class needs to support. An interface is defined using the keyword interface. The members defined in an interface contain only definition, no implementation. The members of an interface are all public by default, any other access specifier cannot be used. See code below:
Public interface IVehicle //As a convention, an interface is prefixed by letter I
{
Boolean HasFourWheels()
}
Time to discuss the Difference between Abstract Class and Interface
1) A class may inherit only one abstract class, but may implement multiple number of Interfaces. Say a class named Car needs to inherit some basic features of a vehicle, it may inherit from an Aabstract class named Vehicle. A car may be of any kind, it may be a vintage car, a sedan, a coupe, or a racing car. For these kind of requirements, say a car needs to have only two seats (means it is a coupe), then the class Car needs to implement a member field from an interface, that we make, say ICoupe.
2) Members of an abstract class may have any access modifier, but members of an interface are public by default, and cant have any other access modifier.
3) Abstract class methods may OR may not have an implementation, while methods in an Interface only have a definition, no implementation.
Monday, January 19, 2009
7 Tips For Unstoppable Motivation And Enduring Success
One of the most important aspects of success is the ability to visualize your path and stay focused on your goal until you reach it.
2. The sooner you envision your dreams and develop a plan to turn them into reality, the faster you will accomplish your goals. Mental pictures are a mechanism to lead you down the path of true independence and motivation.
Procrastination is a self-defeating behavior that develops in part due to low self-esteem and fear of failure. Your imagination is like a preview of your future.
If you don't use your imagination your life will remain mundane and unfulfilling.
3. Overcoming procrastination is the first step in helping you create the lifestyle you desire. You must change the habits and behaviors that led you to procrastinate in the first place.
Change is a slow process so be sure to reward yourself along the way for small achievements.
Instead of focusing on the difficulty of a large task, break it into smaller jobs and create a timeline for finishing them.
4. Several small jobs done over time are much more manageable that one large task with no end in sight.
You'll be astonished at how much you can get done if you concentrate on one thing at a time instead of cluttering your mind with multiple tasks.
Try tackling the more undesirable tasks early in the day so that by afternoon you can pursue more pleasant activities.
5. Relieve yourself of the pressure created by clutter in your office or home. Develop a filing system, rid yourself of unnecessary papers, and give yourself an organized place to work.
When you exercise self-discipline in your surroundings as well as your behaviors, you will make major strides in accomplishing your goals in a shorter period of time.
No matter what is happening around you, keep your mind focused on the reward you'll receive by reaching your goals.
6. If people or outside forces distract you, use the power of the human mind to block out what impedes your progress and concentrate solely on the task at hand.
You will make remarkable progress by refusing to let others alter the path you have chosen.
Overcoming procrastination and staying motivated is the way to lifetime success and happiness. You'll achieve your goals rapidly when you stay focused on your destination and the rewards that will follow.
7. Review your habits and way of thinking to determine what you are visualizing most of the time. If your visions do not lead you in the direction of accomplishing your goals, then you must change them.
Discipline yourself to concentrate on your goals the majority of the time, and if you stray from the path, get promptly back on.
Imagine what the rewards will be when you finally reach your destination and keep that thought foremost in your mind.
Procrastination is of no use to you in your quest to fulfill your dreams. Lose those old habits and replace them with habits that lead to self-motivation and control over your life.
by: Peter Murphy
Monday, October 6, 2008
AMD introduces the fast and furious The AMD FireStream 9250
Here’s presenting a gen-next stream processor from AMD - The AMD FireStream 9250. The processor is especially designed to make the computing experiencing super-fast and high-quality.
Here’s presenting a gen-next stream processor from AMD – The AMD FireStream 9250. The processor is especially designed to make the computing experiencing super-fast and high-quality. The processor was introduced by AMD at the International Supercomputing Conference held in Germany.
AMD FireStream 9250 empowers high-performance computing (HPC) by including a second-generation double-precision floating point hardware implementation, thereby ‘breaking the one teraflop barrier for single precision performance’ and delivering more than 200 gigaflops, racing ahead the performance put up by FireStream 9250’s predecessor FireStream 9170.
The latest processor delivers an extraordinary eight gigaflops per watt performance rate, consumes less than 150 watts of power! It uses just one PCI slot and owing to its ‘compact’ size, it can be used in small 1U servers as well large servers, even in desktop systems and workstations. The AMD FireStream 9250’s compact size makes it ideal for small 1U servers as well as most desktop systems, workstations and larger servers and it features 1 GB of GDDR3 memory, enabling developers to handle large, complex problems.
1 GB of GDDR3 memory makes handling of big and complicated problems easier for developers. Indispensable and crucial workloads like financial analysis or seismic processing can now be done faster and with complex work getting processed easily, the time-period of getting results has been reduced to give out a faster outcome with the help of the latest processor from AMD. As explained by AMD “developers are reporting up to a 55x performance increase on financial analysis codes as compared to processing on the CPU alone, which supports their efforts to make better and faster decisions. Additionally, the use of flexible GPU technology rather than custom accelerators assists those creating application-specific systems to enhance and maintain their solutions easily.”
The series of FireStream is also open to developers to accelerate and elevate AMD FireStream, ATI FireGL, ATI Radeon and GPUs; via the AMD Stream SDK. To help developers to access and enhance on the tools, AMD has also published interfaces for its high-level API language, intermediate language, and instruction set architecture; and the AMD Stream SDK’s Brook+ front-end which are available as open source code.
The FireStream 9250 along with its SDK will be made available by AMD in the third quarter of 2008 at $999 USD MSRP. However, AMD FireStream 9170, the industry’s first GP-GPU with double-precision floating point support AMD FireStream 9170 is already available for $1,999 USD.
Thanks and Regards,
Aman Bindal
GTalk IM: bindal.aman
AOL IM: bindalaman
Mob: (+91)9876489775
"Live everyday with enjoyment, We don't know what tomorrow will give us."
Space command must to check China
NEW DELHI: With China developing anti-satellite (ASAT) missiles, lasers and other offensive space capabilities, India has no option but to be fully prepared for "star wars" in the future.
The creation of just "an integrated space cell", announced by defence minister A K Antony last week, will just not do towards achieving this objective. What is needed is a full-fledged tri-service space command for effective tactical, operational and strategic exploitation of the "final frontier".
The disquiet among the Indian military brass over China's deadly counter-space military programme, with "direct-ascent" ASAT missiles, hit-to-kill "kinetic" and directed-energy laser weapons, came clearly through on Monday.
"China's space programme is expanding at an exponentially rapid pace in both offensive and defensive content," said army chief general Deepak Kapoor, adding that space was increasingly becoming the "ultimate military high ground" to dominate in the wars of the future.
Holding that it should be India's endeavour to "optimize space applications for military purposes" at a seminar on "Indian military and space", Gen Kapoor said the establishment of a tri-service space command "is required in the future".
Integrated defence staff chief Lt-General H S Lidder, in turn, added, "With time, we will get sucked into the military race to protect space assets and inevitably there will be a military contest in space. In a life-and-death scenario, space will provide the advantage."
India, of course, has been painfully slow to react to the huge Chinese strides in the military use of space, which was rudely brought home by its January 2007 test of an ASAT weapon, despite having a robust civilian space programme for several years.
India does not even have dedicated military satellites till now, with the armed forces depending on the "dual use" Cartosat-I, Cartosat-II and the recently-launched Cartosat-IIA for their Rs 1,000-crore satellite-based surveillance and reconnaissance (SBS) programme.
With ISRO finally promising to launch dedicated military satellites in the near future, defence scientists are also experimenting with some "high-power laser weapons", say sources. But the operational use of such star wars-like weapons is still several years away.
India's sheer lack of strategic defence planning is exemplified by the fact that though the armed forces, especially the IAF, have been clamouring for an aerospace command for several years now, it remains a mere pipedream.
Finally, just last week, Antony declared that an integrated defence space cell would be created to protect "the growing threat to our space assets". The Defence Space Vision-2020, on its part, identifies just intelligence, reconnaissance, surveillance, communication and navigation as the thrust areas in the first phase till 2012.
India certainly needs effective utilization of space for "real-time" military communications and reconnaissance missions to keep closer tabs on troop movements, missile silos, military installations and airbases of neighbouring countries.
But this should be followed soon after by other uses of space like missile early-warning, delivery of precision-guided munitions through satellite signals, jamming enemy networks and, of course, ASAT capabilities.
Thanks and Regards,
Aman Bindal
GTalk IM: bindal.aman
AOL IM: bindalaman
Mob: (+91)9876489775
"Live everyday with enjoyment, We don't know what tomorrow will give us."
Tips to Have Your Best Year Ever
Powerful Tips to Help You Have, Your Best Year Ever
Here are 3 powerful steps you can take to free yourself from frustration and to start enjoying the good life so many are enjoying right now:
1) Know "where you are." Have you ever been lost in a residential area and no one was around to ask for directions? Now if you are somewhat familiar with the area, it’s easy to just turn around here and there and find your way back. But the worst part about being lost is when we are lost and we haven't a clue where we are.
So, where exactly are you on your journey now? Do you know exactly how much money you owe? And how many assets you have? What are your strengths? And what are your weaknesses? Here’s a good exercise to help you know "where you are":
Draw a map of your life and make every square a city. Name each square with an aspect of your life. One city can be your family, friends, knowledge of your field, spirituality, work, charity, financial, etc. Then rate each city from one to ten. Ten means you are doing extremely well, and one means it needs immediate help.
What I just shared with you is like having a balance sheet for your life. Put all your weaknesses on one side and your strengths on the other side. Put your strengths to work and strengthen your weaknesses. You can read more books, go back to school or find a mentor.
Perhaps you can learn 50 to 100 power words this year in order to get a verbal advantage. Whatever you do, keep in mind that a better year begins with a better you.
2) Do an inventory of friends. That’s right. Make a list of who your friends are, and how they relate to the direction your life is going in. When companies want to increase their revenue, they get rid of unnecessary employees or ones that are holding them back. So when you are ready to increase your worth, you need to get rid of unnecessary friends. I am talking about those that only cause you grief and are a pain in the "you know what."
If you want to accomplish great things, you need to surround yourself with great people or people who have accomplished great things. You might say, “well, how do I find these great achievers you are talking about?” If you own a copy of No Condition is Permanent, refer to it for the answer.
You and I know fully well that some so-called friends are not worth the aggravation. They are draining, and they sap the life out of you. Consider this: Small people are always talking about things, but great people talk about ideas and concepts. Do you find yourself mentally stimulated when you are with your friends? If you are not, then you should be.
3) Quit killing time. Have you ever heard people say, “I'm just killing time.” Those people should be on death row for first degree murder. If they only realized how precious time really is. I have a wealthy friend who once told me that he can make millions of dollars any time he wants. He can purchase more homes, cars, and other luxuries. But the only thing he can never buy himself is more time.
His point is that he values his time more than his money. Wow! People who have little regard for time always find themselves engaging in activities that have nothing to do with improving their lives or that of those around them. They are routine people. They just do the same old things; they are just going through the daily motions. They love to shoot the breeze and just chill.
Listen, you are entering a new year, and you are not getting any younger. You may have lost so many opportunities. As a reader of my newsletter, you are important to me. I can’t stand by and watch you squander your time and procrastinate. That’s why I am encouraging you to find out "where you are" and start taking action to change your life. Take my advice. Inventory your friends and stop killing time.
I wish you in credible success!
Aman Bindal
GTalk IM: bindal.aman
AOL IM: bindalaman
Mob: (+91)9876489775
"Live everyday with enjoyment, We don't know what tomorrow will give us."