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

  • Home
  • SEARCH
  • 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 3357588
In Process

The Archive Base Latest Questions

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

In college today we made a simple forum in procedural PHP. My homework is

  • 0

In college today we made a simple forum in procedural PHP. My homework is to make it so that it’s in OOP (for comparison), this is where I’m stuck.

In OOP a class should only do one thing, right? So a Topic class should allow a topic to be created, set whether replies are allow, and get its replies…

This is what I got so far,

<?php

abstract class Thread {

    protected $_name;   //thread name
    protected $_text;
    protected $_author;
    protected $_allowReplies = true;
    protected $_replies = array();


    function  __construct($name) 
    {
        $this->setName($name);
    }


    protected function setAuthor(User $author)
    {

    } //edited


    function setAllowReplies($replies)
    {
        if (is_bool($replies)) {
            $this->_allowReplies = $replies;
        }
        else
        {
            return false;
        }
    }

    function  setName($name)
    {
        $this->_name = $name;
    }

    function addReply($reply)
    {
        return $this_replies[] = $reply;
    }

    function  makeThread()      //builds up array of values to add to database
    {
        $values =  array();
        //add to database here
    }
}
?>

What I don’t understand is, do I now have to create a class to add the values to the database and an abstract class to add Authors (using Type hinting .etc), or can I just do it here?

(The above class is incomplete because I got halfway and thought I was doing it wrong)

What I’m basically trying to say is, am I designing the above class correctly?

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

    In OOP a class should only do one thing, right?

    Not quite. A class gathers methods and properties that constitute an object. It is perfectly valid for an object of a particular class to be able to do more than just a single task.

    What I don’t understand is, do I now have to create a class to add the values to the database and an abstract class to add Authors (using Type hinting .etc), or can I just do it here?

    You don’t need an extra class to add a thread or its values to the database (you could, though). Simply offer interfaces (i.e. methods) to the world to add and manipulate a thread.
    Take the author as an example:

    /*
     * Assigns the thread to the specified author
     * Returns boolean
     */
    public function set_author(Author $a)
    {
        // Forge you SQL query based on the author $a's data and
        // send it to your database
    
        // How this is done heavily depends on your table topology
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a college student doing a Java homework. I've created this program that allows
I'm a blind college student who is taking an introduction to programming class that
Today in my college a teacher asked me a question. He wrote this code
In college I've had numerous design and UML oriented courses, and I recognize that
In college, my senior project was to create a simple 2D game engine complete
I've learned in College that you always have to free your unused Objects but
I am a college student at a school that teaches mainly in Java. One
I work at a college that uses an intranet based student management solution not
Back in college, only the use of pseudo code was evangelized more than OOP
Today I had an epiphany, and it was that I was doing everything wrong.

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.