Java Inheritance: empty method in parent class The Next CEO of Stack OverflowIs Java “pass-by-reference” or “pass-by-value”?Prefer composition over inheritance?Java inner class and static nested classHow do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?Understanding Python super() with __init__() methodsPython class inherits objectHow do I convert a String to an int in Java?Creating a memory leak with Java

Why was Sir Cadogan fired?

What happens if you break a law in another country outside of that country?

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

How should I connect my cat5 cable to connectors having an orange-green line?

Calculate the Mean mean of two numbers

How seriously should I take size and weight limits of hand luggage?

What difference does it make matching a word with/without a trailing whitespace?

Another proof that dividing by 0 does not exist -- is it right?

Ising model simulation

Oldie but Goldie

Can this transistor (2N2222) take 6 V on emitter-base? Am I reading the datasheet incorrectly?

Could a dragon use its wings to swim?

Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico

Raspberry pi 3 B with Ubuntu 18.04 server arm64: what pi version

pgfplots: How to draw a tangent graph below two others?

Prodigo = pro + ago?

Could you use a laser beam as a modulated carrier wave for radio signal?

Why can't we say "I have been having a dog"?

Avoiding the "not like other girls" trope?

Can Sri Krishna be called 'a person'?

Physiological effects of huge anime eyes

Is it correct to say moon starry nights?

Cannot restore registry to default in Windows 10?

Are British MPs missing the point, with these 'Indicative Votes'?



Java Inheritance: empty method in parent class



The Next CEO of Stack OverflowIs Java “pass-by-reference” or “pass-by-value”?Prefer composition over inheritance?Java inner class and static nested classHow do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?Understanding Python super() with __init__() methodsPython class inherits objectHow do I convert a String to an int in Java?Creating a memory leak with Java










0















I was wondering if it is frowned upon to have an empty function in a parent class for child classes to override if they needed it? I personally think the use case below justifies it -



class Foo 

void performAdditionalChecksIfNeeded(String decrypted)


void validate(String encrypted)
final String decrypted = decryptIfProperlyEncrypted(encrypted);
performAdditionalChecksIfNeeded(decrypted);



class Bar extends Foo
@override
void performAdditionalChecksIfNeeded(String decrypted)
// Additional validation logic




I'm aware that Bar class could've simply overridden validate() and called super.validate() to eliminate the need of the empty function in Foo. The reason why I had the code arranged this way is that decryptIfProperlyEncrypted uses a library that I wanted to keep only in the Foo class due to separation of concern, performance concerns (decryption), and code duplication avoidance. In other words, if performAdditionalChecksIfNeeded didn't exist in Foo I'd have to perform the decryption again in Bar.










share|improve this question

















  • 1





    I don't see why it should be a problem. There are more functional alternatives, but an empty overridable method is a reasonable approach to some problems.

    – khelwood
    Mar 8 at 19:26
















0















I was wondering if it is frowned upon to have an empty function in a parent class for child classes to override if they needed it? I personally think the use case below justifies it -



class Foo 

void performAdditionalChecksIfNeeded(String decrypted)


void validate(String encrypted)
final String decrypted = decryptIfProperlyEncrypted(encrypted);
performAdditionalChecksIfNeeded(decrypted);



class Bar extends Foo
@override
void performAdditionalChecksIfNeeded(String decrypted)
// Additional validation logic




I'm aware that Bar class could've simply overridden validate() and called super.validate() to eliminate the need of the empty function in Foo. The reason why I had the code arranged this way is that decryptIfProperlyEncrypted uses a library that I wanted to keep only in the Foo class due to separation of concern, performance concerns (decryption), and code duplication avoidance. In other words, if performAdditionalChecksIfNeeded didn't exist in Foo I'd have to perform the decryption again in Bar.










share|improve this question

















  • 1





    I don't see why it should be a problem. There are more functional alternatives, but an empty overridable method is a reasonable approach to some problems.

    – khelwood
    Mar 8 at 19:26














0












0








0








I was wondering if it is frowned upon to have an empty function in a parent class for child classes to override if they needed it? I personally think the use case below justifies it -



class Foo 

void performAdditionalChecksIfNeeded(String decrypted)


void validate(String encrypted)
final String decrypted = decryptIfProperlyEncrypted(encrypted);
performAdditionalChecksIfNeeded(decrypted);



class Bar extends Foo
@override
void performAdditionalChecksIfNeeded(String decrypted)
// Additional validation logic




I'm aware that Bar class could've simply overridden validate() and called super.validate() to eliminate the need of the empty function in Foo. The reason why I had the code arranged this way is that decryptIfProperlyEncrypted uses a library that I wanted to keep only in the Foo class due to separation of concern, performance concerns (decryption), and code duplication avoidance. In other words, if performAdditionalChecksIfNeeded didn't exist in Foo I'd have to perform the decryption again in Bar.










share|improve this question














I was wondering if it is frowned upon to have an empty function in a parent class for child classes to override if they needed it? I personally think the use case below justifies it -



class Foo 

void performAdditionalChecksIfNeeded(String decrypted)


void validate(String encrypted)
final String decrypted = decryptIfProperlyEncrypted(encrypted);
performAdditionalChecksIfNeeded(decrypted);



class Bar extends Foo
@override
void performAdditionalChecksIfNeeded(String decrypted)
// Additional validation logic




I'm aware that Bar class could've simply overridden validate() and called super.validate() to eliminate the need of the empty function in Foo. The reason why I had the code arranged this way is that decryptIfProperlyEncrypted uses a library that I wanted to keep only in the Foo class due to separation of concern, performance concerns (decryption), and code duplication avoidance. In other words, if performAdditionalChecksIfNeeded didn't exist in Foo I'd have to perform the decryption again in Bar.







java inheritance polymorphism






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 19:22









ddolceddolce

338418




338418







  • 1





    I don't see why it should be a problem. There are more functional alternatives, but an empty overridable method is a reasonable approach to some problems.

    – khelwood
    Mar 8 at 19:26













  • 1





    I don't see why it should be a problem. There are more functional alternatives, but an empty overridable method is a reasonable approach to some problems.

    – khelwood
    Mar 8 at 19:26








1




1





I don't see why it should be a problem. There are more functional alternatives, but an empty overridable method is a reasonable approach to some problems.

– khelwood
Mar 8 at 19:26






I don't see why it should be a problem. There are more functional alternatives, but an empty overridable method is a reasonable approach to some problems.

– khelwood
Mar 8 at 19:26













1 Answer
1






active

oldest

votes


















0














Why not use composition over inheritance in this case? The only thing Foo class seems to be doing is the decryption. I would use it in Bar class as a dependency.






share|improve this answer























  • The decryption method throws an exception if the encrypted string made no sense, in some of our use cases that is the only validation needed (to see if something is properly encrypted)

    – ddolce
    Mar 8 at 20:11











  • I don't see it as a validation, it is a decryption operation that can go wrong if the data isn't valid. This operation could be encapsulated inside a class and used where it is necessary.

    – Diego Marin
    Mar 8 at 20:18











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069689%2fjava-inheritance-empty-method-in-parent-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Why not use composition over inheritance in this case? The only thing Foo class seems to be doing is the decryption. I would use it in Bar class as a dependency.






share|improve this answer























  • The decryption method throws an exception if the encrypted string made no sense, in some of our use cases that is the only validation needed (to see if something is properly encrypted)

    – ddolce
    Mar 8 at 20:11











  • I don't see it as a validation, it is a decryption operation that can go wrong if the data isn't valid. This operation could be encapsulated inside a class and used where it is necessary.

    – Diego Marin
    Mar 8 at 20:18















0














Why not use composition over inheritance in this case? The only thing Foo class seems to be doing is the decryption. I would use it in Bar class as a dependency.






share|improve this answer























  • The decryption method throws an exception if the encrypted string made no sense, in some of our use cases that is the only validation needed (to see if something is properly encrypted)

    – ddolce
    Mar 8 at 20:11











  • I don't see it as a validation, it is a decryption operation that can go wrong if the data isn't valid. This operation could be encapsulated inside a class and used where it is necessary.

    – Diego Marin
    Mar 8 at 20:18













0












0








0







Why not use composition over inheritance in this case? The only thing Foo class seems to be doing is the decryption. I would use it in Bar class as a dependency.






share|improve this answer













Why not use composition over inheritance in this case? The only thing Foo class seems to be doing is the decryption. I would use it in Bar class as a dependency.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 19:30









Diego MarinDiego Marin

146111




146111












  • The decryption method throws an exception if the encrypted string made no sense, in some of our use cases that is the only validation needed (to see if something is properly encrypted)

    – ddolce
    Mar 8 at 20:11











  • I don't see it as a validation, it is a decryption operation that can go wrong if the data isn't valid. This operation could be encapsulated inside a class and used where it is necessary.

    – Diego Marin
    Mar 8 at 20:18

















  • The decryption method throws an exception if the encrypted string made no sense, in some of our use cases that is the only validation needed (to see if something is properly encrypted)

    – ddolce
    Mar 8 at 20:11











  • I don't see it as a validation, it is a decryption operation that can go wrong if the data isn't valid. This operation could be encapsulated inside a class and used where it is necessary.

    – Diego Marin
    Mar 8 at 20:18
















The decryption method throws an exception if the encrypted string made no sense, in some of our use cases that is the only validation needed (to see if something is properly encrypted)

– ddolce
Mar 8 at 20:11





The decryption method throws an exception if the encrypted string made no sense, in some of our use cases that is the only validation needed (to see if something is properly encrypted)

– ddolce
Mar 8 at 20:11













I don't see it as a validation, it is a decryption operation that can go wrong if the data isn't valid. This operation could be encapsulated inside a class and used where it is necessary.

– Diego Marin
Mar 8 at 20:18





I don't see it as a validation, it is a decryption operation that can go wrong if the data isn't valid. This operation could be encapsulated inside a class and used where it is necessary.

– Diego Marin
Mar 8 at 20:18



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069689%2fjava-inheritance-empty-method-in-parent-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't find variable: document ReactNative Js2019 Community Moderator ElectionReactNative: how to center text?Can't find variable: navigate - ReactNative navigationReact Native error: “Can't find variable: TouchableHighlight”How to use Expo.DocumentPicker.getDocumentAsync properly. [Expo] [ReactNative]Can't find variable: regeneratorRuntime (ReactNative)Reactnative Expo It is advisable for a StartUp?Can't find variable : Self / Can't install firebaseNPM Install Error in installing ReactNative CLIContacts Displaying in App using ReactnativeFacebook login error: can't find variable: Alert

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices