Solved

why is it wrong to combine interface and abstract class; acquire the method externally?

Posted on 2016-07-23
4
133 Views
Last Modified: 2016-08-08
interface printer{
  printToScreen(){}
  printToPrinter(){}
 printToCellPhone(){}
 sendToFax(){}
}



computer implements printer
cableBox tv box implements printer
cable router implements router


all 3 of these classes must print
may be easier to create abstract class than to keep on creating new methods and copy pasting those methods into all classes

abstract class AllPrintingMehods(){
 printToScreen(){}
  printToPrinter(){}
 printToCellPhone(){}
 sendToFax(){}

}




why is it wrong to combine interface and abstract class

why is wrong to acquire the method externally?
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:gurpsbassi
gurpsbassi earned 125 total points
ID: 41726062
you have to think about what your desired architecture is.

You can use abstract classes where there is a true "is-a" relationship modelled. Interfaces are normally used to define contracts/behaviour where there is a "can-do" relationship hence most interfaces in the java api are defined with the ending "*able" e.g. serializable,  Cloneable.
0
 
LVL 9

Accepted Solution

by:
Subrat (C++ windows/Linux) earned 250 total points
ID: 41726221
Interface never have any definition, only having pure virtual functions. As already told "can-do"

But abstract class is having atleast one pure virtual and other may or mayn't be . We need it to restrict creation of object.

Again, if know some functions are reusable by derivatives, and some are need specific implementation, then Abstract class is the case.

If all fuctions are abstract, then ur interface.
0
 
LVL 16

Assisted Solution

by:gurpsbassi
gurpsbassi earned 125 total points
ID: 41726223
Again, if know some functions are reusable by derivatives, and some are need specific implementation, then Abstract class is the case.

If all fuctions are abstract, then ur interface.

this should not be the deciding factor for going for abstract class v interface.

Just putting functionality into a abstract class for reuse is not a good pattern to follow. You end up with a class with a bunch of meaningless  methods which could easily be replaced with a class containing static methods.
0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 125 total points
ID: 41726543
Hi rgb192;

Have a look at this Microsoft documentation, Recommendations for Abstract Classes vs. Interfaces.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
what type of pointer is this pointer? 3 29
PowerShell:  Use of subproperties in a Select statement 7 64
Firefox and firebub 5 22
Java regex 5 17
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question