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 3356270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:29:40+00:00 2026-05-18T02:29:40+00:00

This may be a dumb question but i’ll give it a go anyway. This

  • 0

This may be a dumb question but i’ll give it a go anyway.

This is for PHP5. Lets say i have two classes Member.class.php and Forum.class.php and have a method called returnDate($queryDate) that can be used in the two classes – for the member class it returns users last seen date and for the forum class it returns last answered. For example, Member: Jonny - last seen **2 mins ago**. Forum post: last answered **10 mins ago**.

Im assuming it’s a bad idea to put this method into the two classes to avoid duplication so im wondering is this where an interface class would come in handy? Or do I do something obvious like create a class for the site to put it in e.g. Website.class.php. Just trying to further my understanding thanks.

  • 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-18T02:29:41+00:00Added an answer on May 18, 2026 at 2:29 am

    Assuming that the two functions are essentially identical…

    My suggestion: Composition > Inheritance.

    Create a ‘DateHelper’ class, and make an instantiation of it a component of each of those classes. That way you’ve got once place for the code to live (DRY!) and it’s clear that there’s some shared functionality between the two classes.

    You could also make the method static, and call DateHelper::returnDate($x), but I try to minimise use of static functions where I can.

    This approach has the advantage of letting you add more date-related functionality, and keeping it in a single place that is comprehensible as being about date-related stuff.

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

Sidebar

Related Questions

This may seem like a dumb question but I have IDLE and I'm trying
This may be a dumb question, but I really have no idea and I'm
This may be a really dumb question but I'm just starting to learn the
I know this may be a dumb question, but my background is more in
This may be a very dumb question but I can't seem to get it
this may be a dumb question, but I can't seem to find the answer.
I feel like this may be a dumb question, but it's late and my
This may be a completely dumb question, but I've seen a couple examples declaring
I have quick question, and it may sound dumb. But for the love of
I feel really dumb for asking this question, but here it goes. I have

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.