1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What's the point of abstract classes?

Discussion in 'General PHP and MySQL Discussions' started by TheBigK, Jun 24, 2014.

  1. TheBigK

    TheBigK Well-Known Member

    You aren't defining anything in the methods anyway! So why create the abstract class in first place and then have the child extend its functionality? I can do almost everything with the child class; without defining the abstract class.
     
  2. Jeremy P

    Jeremy P Well-Known Member

    el canadiano, Aayush and Bob like this.
  3. CJ.Wurtz

    CJ.Wurtz Member

    It helps ensure consistency in related child classes.

    As an example, say for instance you wanted a application to support several databases. So you want a wrapper class for all the DB methods you need. You write a wrapper for MySQL, and ones for MSSql. Using an abstract you can ensure that each different wrapper implementation has the same methods, with the same parameters. While you could do it without, it leaves room one of those wrapper classes to miss a required methods, use different naming schema, miss a parameter, etc.

    Also say you release this, and someone else wants to come along and use say... MongoDB. Having that abstract will hopefully give them all they need to fully implement the wrapper for the new database, and know exactly what methods they need to implement to fully support it in the application
     
    Aayush, TheBigK and AndyB like this.
  4. TheBigK

    TheBigK Well-Known Member

    Thanks. That makes sense now.
     

Share This Page