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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:01:00+00:00 2026-05-25T02:01:00+00:00

Why would you use such abstract? Does it speed up work or what exactly

  • 0

Why would you use such abstract? Does it speed up work or what exactly its for?

// file1.php
abstract class Search_Adapter_Abstract {
    private $ch = null;
    abstract private function __construct()
    {
    }       
    abstract public funciton __destruct() { 
      curl_close($this->ch);
    }
    abstract public function search($searchString,$offset,$count);
}

// file2.php
include("file1.php");
class abc extends Search_Adapter_Abstract
{
    // Will the curl_close now automatically be closed?

}

What is the reason of extending abstract here? Makes me confused. What can i get from it now?

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

    You can use abstract classes to define and partially implement common tasks that an extended class should do. Since explaining it is difficult without an example, consider this:

    Without abstract classes, you would have to define two basic classes with the same methods and implementation. Since OOP is all about preventing code duplication, this is quite wrong:

    class Car {
      public $brand = 'mercedes';
    
      public function gasPerMile($weight) 
      {
        // Useless calculation, purely for illustrating
        $foo = $weight * 89 / 100;
        return $foo;
      }
    
      public function carSpecificFunction() 
      {
        // Only present in class Car
      }
    }
    
    class Truck {
      public $brand = 'MAN';
    
      public function gasPerMile($weight) 
      {
        // Useless calculation, purely for illustrating
        $foo = $weight * 89 / 100;
        return $foo;
      }
    
      public function truckSpecificFunction() 
      {
        // Only present in class Truck
      }
    }
    

    Now you have some common properties and methods, which are duplicated in two classes. To prevent that, we could define an abstract class from which Car and Truck are extended. This way, common functionalities are kept in one place and the extended classes will implement specific properties and methods for either the Truck or the Car.

    abstract class Vehicle {
      abstract public $brand;
    
      public function gasPerMile($weight) 
      {
        // Useless calculation, purely for illustrating
        $foo = $weight * 89 / 100;
        return $foo;
      }
    }
    

    This way, you ensure that atleast every class that extends Vehicle has to have a brand specified and the common gasPerMile() method can be used by all extended classes.

    Of course, this is a simple example, but hopefully it illustrates why abstract classes can be useful.

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

Sidebar

Related Questions

Does such function exist? I created my own but would like to use an
Given a string file path such as /foo/fizzbuzz.bar , how would I use bash
Let's use a quite plain example with employees and company(-ies) . public abstract class
I have this C# class structure that I would like to refactor to use
I would use a multi dimensional gaussian modell for regression. Rasmussen has a book
Why one would use one of the following packages instead of the other? Java
I thought I would use a stored routine to clean up some of my
In .NET I would use System.Diagnostics.Trace... What would I use in C or C++
still trying to find where i would use the yield keyword in a real
I was wondering what you would use to scrub a database of all test

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.