search
HomeBackend DevelopmentPHP Tutorial(8) Object-oriented design principle four

one. Replacement principles:
1. Subclasses must be replaceable with their base classes and appear anywhere where the parent class can appear.
2. Problems that need to be solved by the LSP principle:
a. How to design inheritance correctly
b. How to obtain the best inheritance hierarchy
c. Avoid the designed class hierarchy from falling into a situation that does not comply with OCP principles
3. Ways to comply with this principle:
a. All methods of the parent class must be implemented or rewritten in the subclass, and the derived class only implements the methods declared in its abstract class, but cannot give redundant method definitions or implementations.
b. Only parent class objects should be used in client programs and subclass objects should not be used directly. This enables runtime binding. (Dynamic polymorphism)

2. Example:

<?php abstract class Cache{
    /*
     * 设置一个缓存变量
     *
     * @param String $key  缓存key
     * @param mixed $value 缓存内容
     * @param int $expire 缓存时间(秒)
     * return boolean 是否缓存成功
     */
    public abstract function set($key,$value,$expire=60);

    /*
     * 获得一个已经缓存的变量
     * @param String $key 缓存key
     * @return mixed 缓存内容
     */
    public abstract function get($key);

    /*
     * 删除一个已经缓存的变量
     * @return boolean 是否删除成功
     */
    public abstract function del($key);

    /*
     * 删除全部缓存变量
     * @return boolean 是否删除成功
     */
    public abstract function delAll($key);

    /*
     * 检测是否已经存在对应的缓存
     */
    public abstract function has($key);
}

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above has introduced the fourth object-oriented design principle (8), including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
C语言return的用法详解C语言return的用法详解Oct 07, 2023 am 10:58 AM

C语言return的用法有:1、对于返回值类型为void的函数,可以使用return语句来提前结束函数的执行;2、对于返回值类型不为void的函数,return语句的作用是将函数的执行结果返回给调用者;3、提前结束函数的执行,在函数内部,我们可以使用return语句来提前结束函数的执行,即使函数并没有返回值。

SQL中的identity属性是什么意思?SQL中的identity属性是什么意思?Feb 19, 2024 am 11:24 AM

SQL中的Identity是什么,需要具体代码示例在SQL中,Identity是一种用于生成自增数字的特殊数据类型,它常用于唯一标识表中的每一行数据。Identity列通常与主键列配合使用,可以确保每条记录都有一个独一无二的标识符。本文将详细介绍Identity的使用方式以及一些实际的代码示例。Identity的基本使用方式在创建表时,可以使用Identit

SpringBoot怎么监听redis Key变化事件SpringBoot怎么监听redis Key变化事件May 26, 2023 pm 01:55 PM

一、功能概览键空间通知使得客户端可以通过订阅频道或模式,来接收那些以某种方式改动了Rediskey变化的事件。所有修改key键的命令。所有接收到LPUSHkeyvalue[value&hellip;]命令的键。db数据库中所有已过期的键。事件通过Redis的订阅与发布功能(pub/sub)来进行分发,因此所有支持订阅与发布功能的客户端都可以在无须做任何修改的情况下,直接使用键空间通知功能。因为Redis目前的订阅与发布功能采取的是发送即忘(fireandforget)策略,所以如果你的程

function是什么意思function是什么意思Aug 04, 2023 am 10:33 AM

function是函数的意思,是一段具有特定功能的可重复使用的代码块,是程序的基本组成单元之一,可以接受输入参数,执行特定的操作,并返回结果,其目的是封装一段可重复使用的代码,提高代码的可重用性和可维护性。

Java中return和finally语句的执行顺序是怎样的?Java中return和finally语句的执行顺序是怎样的?Apr 25, 2023 pm 07:55 PM

源码:publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#输出上述代码的输出可以简单地得出结论:return在finally之前执行,我们来看下字节码层面上发生了什么事情。下面截取case1方法的部分字节码,并且对照源码,将每个指令的含义注释在

iOS的developer版和public版有什么区别?iOS的developer版和public版有什么区别?Mar 01, 2024 pm 12:55 PM

每年Apple发布新的iOS和macOS大版本之前,用户都可以提前几个月下载测试版抢先体验一番。由于公众和开发人员都使用该软件,所以苹果公司为两者推出了developer和public版即开发者测试版的公共测试版。iOS的developer版和public版有什么区别呢?从字面上的意思来说,developer版是开发者测试版,public版是公共测试版。developer版和public版面向的对象不同。developer版是苹果公司给开发者测试使用的,需要苹果开发者帐号才可以收到下载并升级,是

Unpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devicesUnpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devicesSep 04, 2024 pm 06:32 PM

An unpatchable Yubico two-factor authentication key vulnerability has broken the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices. The Feitian A22 JavaCard and other devices using Infineon SLB96xx series TPMs are also vulnerable.All

redis批量删除key值的问题怎么解决redis批量删除key值的问题怎么解决May 31, 2023 am 08:59 AM

遇到的问题:在开发过程中,会遇到要批量删除某种规则的key,例如login_logID(ID为变量),现在需要删除"login_log*"这一类的数据,但是redis本身只有批量查询一类key值的命令keys,但是没有批量删除某一个类的命令。解决办法:先查询,在删除,使用xargs传参(xargs可以将管道或标准输入(stdin)数据转换成命令行参数),先执行查询语句,在将查询出来的key值,当初del的参数去删除。redis-cliKEYSkey*(查找条件)|xargsr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.