Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6134067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:18:33+00:00 2026-05-23T17:18:33+00:00

Having this tasteful class public abstract class CakeSkill { //.. boolean cherry=false; private void

  • 0

Having this tasteful class

     public abstract class CakeSkill 
     {

         //.. 

         boolean cherry=false;

         private void finalMandatoryTouch()
         {        
              cherry=true;
         }                
         abstract public void cook();
     }

A class that extends it would be something like

     class Cheff extends CakeSkill 
     {
         //..

         void cook()
         {
         //..Secret recipe
         }     
     }

But of course this won’t work,

finalMandaroryTouch() hasn’t been called, then no cake will end with a cherry..

[EDIT]

This one could be a solution

       class MemoriousCheff extends CakeSkill 
       {
           //..

           void cook()
           {
               //..Secret recipe
               finalMandatoryTouch();
           }     
       }

but requires :

  • Cheff to have a perfect memory that don’t forget to call finalMandatoryTouch()
  • Making finalMandatoryTouch() to be protected (at least)

[/EDIT]

It would be great! (but no Java) if something like this could be done

  abstract public void cook()   
  {  
    @implementedMethod

    finalMandatoryTouch();        
  }

How can be implemented this useful functionality ?

Thank you very much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:18:33+00:00Added an answer on May 23, 2026 at 5:18 pm

    Change cook to a protected method cookImpl then have a public final method called cook:

    public final void cook()
    {
        cookImpl();
        finalMandatoryTouch();
    }
    
    protected abstract void cookImpl();
    

    That way the subclass only needs to worry about cookImpl, but callers of cook get the cherry on top. Callers not in the same package or class hierarchy won’t even see cookImpl, so won’t be able to call it directly.

    This is the template method pattern, basically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having this class : class Automat { private: // some members ... public: Automat();
Having this model class public class Usuario { #region Atributos private int _intID =
Having this wait declaration: public final native void wait(long timeout) throws InterruptedException; It could
I'm having this problem with this piece of PHP code: class Core { public
Having this design : interface Foo<T> { void doSomething(T t); } class FooImpl implements
I'm having this very odd issue while trying to serialize a class for logging
Having this code : Models paciente.rb class Paciente include SimplyStored::Couch has_many :consultas end consulta.rb
i´m having this error. My header: libtorrent::fingerprint a(LT, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0); class TorrentClass
Having this code p = subprocess.Popen('tail -f /var/log/syslog', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in
Having this button on my page: <input type=button id=Button1 value=OK class=buttonClass width=150px/> and using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.