Last post Oct 18, 2012 02:57 AM by kaushikmaheta
Oct 16, 2012 12:53 AM|joshuait|LINK
I tried how to use abstract class and interface. I am fine now with how to work on these things. But i need to know what is the use these things? Why we need to choose abstract and interface? At what situation we should go for these things?
Oct 16, 2012 01:04 AM|gaikwad_anil1987|LINK
Oct 16, 2012 06:59 AM|gerrylowry|LINK
generally, one might consider defining an interface for the purpose of allowing c# to exhibit
multiple inheritence-like behaviour.
remember, before OOP (Object Oriented
Programming), the art of programming was procedural ... programmers wrote code that implemented some
procedure in a more or less mechanical way.
Example: compute inventory procedure.
step 1: sales person provides data for a sale.
step 2: programmer uses dollar value to update accounting database.
step 3. programmer uses part number and quantity to update inventory database.
step 4: programmer uses dollar value to update payroll database.
procedural programming works; there are likely many millions of perfectly fine working business computer systems that are 100% procedural.
OOP lets programmers model the real world conceptually.
TIMTOWTDI =. there is more than one way to do it
in procedural programming, one gives data to a method, and that method performs some task.
while OOP is in some ways similar, we introduce the idea of a
class ...a class sometimes represents only data but often also has
methods for working with that data in a conceptual way ... over time,
joshuait, this will become clearer to you. for now, it may appear somewhat insane to you.
Example: compute inventory (OOP version) ... TIMTOWTDI =. there is more than one way to do it
step 1: sales person object tells a sale object about a sale.
step 2: the sale object tells the accounting object about the sale.
step 3. the sale object tells the product object about the sale.
step 4: the sale object tells the payroll person object about the sale.
Okay, OOP in many ways looks similar to procedural programming ... however, one difference is that the programmer can now think about designing
models the mimic what humans might do if computers did not exist.
code reuse happens in both OOP and in procedural programming, however, code reuse
may be more likely to occur in OOP.
perhaps more important, programmers and non-programmers can now discuss and design business computer systems together by using the same terminology because the
classes model real world behaviour.
single inheritance scenario
you were driving through a desert and you met a lost stranger who was on foot and likely to die from exposure; you give the stranger a ride; he tells you he is Howard Hughes and he promises to reward you. You assume he was delussional and
drop him off in the city and never see him again. a few years later, a lawyer visits you with a bag of money because it really was Howard Hughes and you have
inherited from him part of his very large fortune.
multiple inheritance scenario
genetically you have inherited your father's good looks and physical strength and your mother's intelligence and musical ability.
i know that's not the best example because you may be thinking of men and women as people ... instead, it might help if you think of them as somewhat separate entities ...
progeny (i.e., babies that we hope we become adults) inherit their characteristics from both the
male parent and the female parent.
just as in c#, inheritance frequently goes back to System.Object, with genetics, simplified, would could write:
adults are homo sapiens
procreating adults are adults who
mate to create progeny
progeny inherit characteristics from one male procreating adult and one
female procreating adult
in OOP, multiple inheritance is more complicated than single inheritance. some computer languages do not make
inheritance easy or even possible; others facilitate multiple inheritance
in different ways. in c++, a subclass can inherit from more than one
in c#, multiple inheritance can be achieved through the employment of
joshuait, you may wish to refer to:
"Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries", Second Edition, Krzysztof Cwalina; Brad Abrams; Addison-Wesley Professional, October
22, 2008; Print ISBN-10: 0-321-54561-3, Print ISBN-13: 978-0-321-54561-9, Web ISBN-10: 0-321-54567-2, Web ISBN-13: 978-0-321-54567-1, Pages in Print Edition: 480
classes are the preferred construct for exposing
The main drawback of
interfaces is that they are much less flexible than
classes when it comes to allowing for evolution of APIs. After you ship an
interface, the set of its members is fixed forever. Any additions to the
interface would break existing types that implement the
A class offers much more flexibility. You can add members to
classes that have already shipped. As long as the method is not
abstract (i.e., as long as you provide a default implementation of the method), any existing derived
classes continue to function unchanged.
note: while the book is mainly applicable to designing API's, much of its information is also applicable generically.
Oct 18, 2012 02:54 AM|nijhawan.saurabh|LINK
Three pillars of OOPS are(We need Classes/Abstract Classes and Interfaces to implement these):
In case you don't know yet, Interfaces cannot have any method definition but Abstract classes can have method implementation
Also you cannot instantiate an Abstract class even though it has method definitions.
Oct 18, 2012 02:57 AM|kaushikmaheta|LINK
learn this link in which explain in easily