Difference between abstract class and the normal class

Hi...........
can anyone tell me use of abstract class instead of normal class
The main doubt for me is...
1.why we are defining the abstract method in a abstract class and then implementing that in to the normal class.instead of that we can straight way create and implement the method in normal class right...../

Class vs. interface
Some say you should define all classes in terms of interfaces, but I think recommendation seems a bit extreme. I use interfaces when I see that something in my design will change frequently.
For example, the Strategy pattern lets you swap new algorithms and processes into your program without altering the objects that use them. A media player might know how to play CDs, MP3s, and wav files. Of course, you don't want to hardcode those playback algorithms into the player; that will make it difficult to add a new format like AVI. Furthermore, your code will be littered with useless case statements. And to add insult to injury, you will need to update those case statements each time you add a new algorithm. All in all, this is not a very object-oriented way to program.
With the Strategy pattern, you can simply encapsulate the algorithm behind an object. If you do that, you can provide new media plug-ins at any time. Let's call the plug-in class MediaStrategy. That object would have one method: playStream(Stream s). So to add a new algorithm, we simply extend our algorithm class. Now, when the program encounters the new media type, it simply delegates the playing of the stream to our media strategy. Of course, you'll need some plumbing to properly instantiate the algorithm strategies you will need.
This is an excellent place to use an interface. We've used the Strategy pattern, which clearly indicates a place in the design that will change. Thus, you should define the strategy as an interface. You should generally favor interfaces over inheritance when you want an object to have a certain type; in this case, MediaStrategy. Relying on inheritance for type identity is dangerous; it locks you into a particular inheritance hierarchy. Java doesn't allow multiple inheritance, so you can't extend something that gives you a useful implementation or more type identity.
Interface vs. abstract class
Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks.
Abstract classes let you define some behaviors; they force your subclasses to provide others. For example, if you have an application framework, an abstract class may provide default services such as event and message handling. Those services allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform. Such functionality might include startup and shutdown tasks, which are often application-dependent. So instead of trying to define that behavior itself, the abstract base class can declare abstract shutdown and startup methods. The base class knows that it needs those methods, but an abstract class lets your class admit that it doesn't know how to perform those actions; it only knows that it must initiate the actions. When it is time to start up, the abstract class can call the startup method. When the base class calls this method, Java calls the method defined by the child class.

Similar Messages

  • Difference between promotional macbook and the normal  priced macbook?

    is there any difference between the promotional ones eg. back to sch promo..and the normal priced macbook? from what i heard there some difference in the component (maybe cheaper components?) they use in the promo macbooks..hope to enlighten me thanks..

    If Apple were making a special MacBook for this promo it would actually cost Apple more from having to make a separate production run not to mention more in technical support.
    The promo is a simple back to school promo. Nothing more.

  • What is the difference between Abstract class and Interface ?

    Hi,
    Could u plz tell me the difference between Abstract class and Interface?
    Thanks in advance.
    Gopi

    Lots.
    An abstract class can contain some method implementations, or indeed all the method implementations. It may contain methods with all the various access modifiers. It cannot be instantiated. A class may inherit from only a single abstract class.
    An interface contains only public method stubs and constants. A class may implement multiple interfaces. An interface cannot (obviously) be instantiated.
    Abstract classes are particularly useful when you need to provide a semi-complete implementation for reuse. Interfaces are used more like types.
    Look at java.util.* for some good examples of the use of both.

  • Difference between abstract classes and interfaces

    I actually wonder about what are the differences between abstract classes and interfaces may somebody give an example code about it?
    and i have one more question how can i use interfaces like multiple inheritance ? i mean when i implement an interface like
    class a extends b implements c,di have to use all c and d methods but what that methods means?
    I mean as i know we cannot make implementations of methods in interfaces
    but for example in runnable interface there is a method like run() and it has been defined somewhere because it knows what to do(i mean when it will run), i just write my code into that method .

    Once you get past the starting point (I am referring to the OP here), there are a few salient differences:
    You can only extend (or generalize) a single superclass; however, you can implement (or realize) multiple interfaces. As such, all things being equal, using an interface in lieu of an abstract class 'frees' your design. Later, if you want the implementor of an interface to inherit from another class, there is not issue.
    Any abstract method specifies a contract. However, abstract classes allow you to also add common behavior to subclasses. This is an overused justification for abstract classes, IMO. You can achieve the same effect using delegation and still having interfaces.
    Always program to interfaces wherever possible. This means that you define an interface and have an implementing class (usually at a minimum). Do not do this for all your classes, but rather the ones that make your system unique (the domain model or M in MVC architecture). This allows you to later change implementation with a minimal amount of refactoring. This is a core precept from the Group of Four and any number of decent programming books.Best of luck.
    - Saish

  • Difference between Abstract Classes Vs Interface

    Hi,
    Can u pls mention all the differences between Abstract Classes and Interface.? I've mentioned the differences I've known here.
    Known Differences:
    (*) An interface cannot implement any methods, whereas an abstract class can.
    (*) A class can implement many interfaces but can have only one superclass
    Can U pls mention at what situation(practical situation) we've to go for abstract class or Interface?
    Tell me the situation when we have to go for abstract class?
    Tell me the situation when we have to go for interface?
    Please Reply me
    Thanks & Regards
    Venkatesh

    There are more differences, and one really important is that abstract classes can also define class variables, while interfaces cannot. I think the question of when to use interfaces or abstract classes is not always easy to answer, but yourself have pointed some tips you should be aware of :
    If you need that some funcionality of the class is derived by more than one "parent" then you should use interfaces, since you cannot extend more than one class.
    If your "superclass" needs to define some class variables then the choice must be made to have a superclass and then extend it. Also this is applicable if there is a method that can be programmed at a higher level (in interfaces you cannot program methods).
    But the answer to the question is still not easy. And remember, you can always mix both tipes, you can extend one class and implement some interfaces.
    Examples or that are very common in the Java API for AWT or Swing components, for example javax.swing.JLabel extends javax.swing.JComponent (that is beacuse a JLabel IS a JComponent and it uses some variables and methods programmed at the JComponent "level") and it also implements some interfaces: Accessible, ImageObserver, MenuContainer, Serializable & SwingConstants.
    I hope this helps.
    Zerjillo

  • Difference between abstract interface and normal interface

    Hello Friends,
    What is the Difference between abstract interface and normal interface?....

    What is the Difference between abstract interface and
    normal interface?....The difference is that you didn't follow convention in the first case. All interfaces are implicitly abstract so you don't have to declare them as such.

  • What's the difference between Java SDK and the Enterprise Edition?

    What's the difference between Java SDK and the Enterprise Edition? Are they both free?

    both r free but they are used in diffrent applications. sdk are used for simple apps that run on your computer while j2e (enterprise edition) are ment for large distributed computer systems that include servers and such. if you don't know the diffrence you probably wont need the the j2e, only the sdk.

  • BCT - how to find the difference between installed BCT and the newest BCT?

    Hi,
    How do I find the difference between installed BCT and the newest BCT?
    or find a description of the newest BCT?
    Thank you.
    - Gunnar

    Hi,
    Thank you for your answer.
    I am aware of the possibilities you mention.
    I am looking for a way to find the parts of the business content that has been modified since I installed our current version WITHOUT installing anything.
    That is for example:
    If F&R business content has been moved from 3.x technology to 7.0
    If there is changes to the F&R content at all
    -> if our current version of business content already contains the newest version of Business Content for F&R, then it is not a prerequirement to an F&R project that we update business content.
    The possibility to see that the only changes might be in the area of SAP HCM ...
    Thank you.
    - Gunnar

  • Exact difference between System status and the user status

    Hi,
    Please tell me the exact difference between System status and the user status .
    how we customize the both in the system
    Thanks & Regards
    Prajith P
    Moderation: Locked. Please, try to find an answer first. See rules of engagement
    Edited by: Joaquin Fornas on Feb 23, 2012 11:14 AM

    Hi,
    As you mentioned there are 2 status can be maintained for documents like Equipment Master, Notification, Maintenance Order & other important business documents.
    In case, client feels that system status is not enough to capture the details of the object, then user status can be used.
    System statuses will be updated automatically based on business transactions which will be done on SAP.
    For example, once the equipment is created, System status would CRTD (Created). If you install the same to some superior equipment or FL, then status would be INST (Installed).
    If you keeping that equipment in Spare, then for that, you have to maintain separate User Status like AVLB (Available in Stock / Spare) so that through IH08, by using User status, you can the report which is available as spare.
    These user status as per the name, should be updated by the user manually.
    Regards,
    Maheswaran.

  • What is the difference between partition-count and the number of caches?

    What is the difference between partition-count and the number of caches in Coherence? Are they same?

    Those are totally orthogonal concepts.
    For more, look at this thread where I answered your other related questions and explain this, too:
    Where can I find the accurate definitions of these terms?
    Best regards,
    Robert

  • [svn] 4112: Further work for FXG to SWF transcoding - checking in some work resulting from collaborating with Kaushal to correct FXG transforms and gradient transforms as well as cater for differences between Java AffineTransform and the SWF Matrix type .

    Revision: 4112
    Author: [email protected]
    Date: 2008-11-14 10:05:42 -0800 (Fri, 14 Nov 2008)
    Log Message:
    Further work for FXG to SWF transcoding - checking in some work resulting from collaborating with Kaushal to correct FXG transforms and gradient transforms as well as cater for differences between Java AffineTransform and the SWF Matrix type.
    QE: Not yet.
    Doc: No
    Checkintests: Pass
    Reviewer: Kaushal
    Modified Paths:
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/dom/GraphicContentNode.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/dom/fills/LinearGradientFillNode.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/dom/fills/RadialGradientFillNode.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/dom/strokes/LinearGradientStrokeNode.j ava
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/dom/strokes/RadialGradientStrokeNode.j ava
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/swf/AbstractFXGGraphics.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/swf/TypeHelper.java
    Added Paths:
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/dom/ScalableGradientNode.java

  • Is there a difference between Statement Cache and the statement handle!

    Hello!
    The OCI statement cache is !session! wide. When I have a sql statement that was used before, I can use this feature.
    But what is the difference between this feature and my statement handle for a certain sql statement that I can store and reuse a second time?
    My stored statement handle is already prepared and the placeholders are bound. The second time I only have to copy new values in the memory positions and do an execute and that's all.
    Thank you in advance
    Wolfgang

    The underlying optimization is the same. When you re-execute a statement, you are reusing the metadata already available in the statement and the cursor already open on the server. If you know exactly the set of statements that you are going to execute repeatedly, you can maintain the cache on your own. (Yes, you save on doing the Bind/Define calls multiple times).
    OCI Statement cache makes it transparent and the application does not need to keep the references/indexes to the relevant statements. Also once a cache size is set, least recently used statements get out of the cache when the cache is full and needs to accommodate more.
    To optimize the bind/defines on the statements from the statement cache, you can use this feature:
    http://www.filibeto.org/sun/lib/nonsun/oracle/11.2.0.1.0/E11882_01/appdev.112/e10646/oci09adv.htm#sthref1358

  • Is there difference between CVI dll and a normal C dll

    Hi All,
    I want to know is there any difference between C dll and CVI dll?
    If any body has idea on this, Pls reply back to me.
    Thanks,
    Harika

    Are you sure about that?  Visual C++ has runtime libraries that need to be deployed in order for an executable to work as described on this MS site:
    http://www.microsoft.com/downloads/details.aspx?fa​milyid=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displa​...
    So I'd be surprised that somehow they manage to statically link all the runtime dependencies for a DLL if they don't/can't do it for an executable.
    Even if you include the runtime support in the distribution, wouldn't they deploy as separate DLL's?   Are you saying that there's static library equivalents for all of VCPP runtime support?
    Menchar
    Message Edited by menchar on 05-21-2010 09:19 AM
    Message Edited by menchar on 05-21-2010 09:21 AM

  • What's the difference between Abstract Class and Interface?

    Dear all,
    Can anyone give me some hints about this topic?
    Thanks.
    Leo

    an abstract class may have some methods already implemented in the abstract class but an interface has no methods implemented
    I think it's just that simple.
    For your design needs, you just choose what you need : )
    Cheers
    Stephen

  • Difference between abstract class and interface

    Hi everyone,
    CAn anyone explain why the following happen????
    Abstract class can have a constructor, Interface cannot.
    Abstract class can have static methods, Interface cannot.

    What are the advantages of defining constant
    variables in Interfaces?Not many.
    Effective Java - Joshua Bloch, Chapter 4, Item #17: Use interfaces only to define types.
    The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implementing a constant interface causes this implementation detail to leak into the class's exported API. It is of no consequence to the users of a class that the class implements a constant interface. In fact, it may even confuse them. Worse, it represents a commitment: if in a future release the class is modified so that it no longer needs to use the constants, it still must implement the interface to ensure binary compatibility. If a nonfinal class implements a constant interface, all of its subclasses will have their namespaces polluted by the constants in the interface.
    In summary, interfaces should only be used to define types. They should not be used to export constants.

Maybe you are looking for

  • Dúvida quanto a sincronização de e-mail POP3 iPhone 4S = MacBook Pro

    Prezados, Tenho um MacBook Pro e iPhone 4S. Gostaria da ajuda para configurar o iPhone para receber e-mails do Terra/UOL (POP3) e depois sincronizar ou transferir estes e-mails "descarregados" no iPhone para o MacBook (uso no MacBook o mail da própri

  • Select rows from the table which don't exist in another table

    Hi, in this relatively simple task I have some problem. I need to get the records from the T1 which don't exist in T2, based on some criteria. here is my query: select a.ordernum, sum(totchg), b.tracknum, rownum from T1 a, T2 b where 1=1 and a.ordern

  • KM API : Creating External Link with Overwriting feature

    Hi, I am using KM API to create an external link on a KM folder. This is the code which I am using for it.     try       pathRID = RID.getRID(p_parent);       collection = (ICollection)p_ResourceFactory.getResource(pathRID, p_ResouceContext);       c

  • Time machines encryption seen as 2 hard drives?

    Hello, i've two different hard drive where i do the time machine backup with encryption. I let time machine handle the entire disk and the encryption process. But everytime i unmount the drive, osx tell me that it is unmounting two partition and ask

  • Upgrading Powerbook G4 from USB 1 to USB 2

    Can someone tell me is it possible to upgrade a Powerbook G4 15" which is fitted with two USB1 ports to USB2, please? I would probably take it to an Apple Store rather than attempt it myself. Thank you.