松耦合的模块化开发有关问题
松耦合的模块化开发问题
现在的web项目越来越复杂,越来越注重项目代码的复用与伸展自如。
比如,一个企业的cms项目,有“文本”模块、“图片”模块、“视频”模块、“身份验证”模块等等,而这些模块之间是相互穿插的,“文本”模块可以有“图片模块”,“视频”模块中需要“身份验证”等等,当这些模块组成一个cms时,依客户要求不同,是分“精简”版、“标准”版、“加强”版等版本的,越复杂的版本,加载的模块越多,但怎样才能保持当模块移除时保证核心库与其它模块正常工作呢?!或者说可以依需求动态加载其它模块?!或者说实现PHP的敏捷开发?!
------解决方案--------------------
这个,只能是考虑的多点。
也就是说,想到全面一些。
也没什么好的办法。
我们每天都在开发,如果能真的综合一下的。是可以的。
------解决方案--------------------
我一般是这么解决的,自定义模型和封装类
如果你懂MVC,那么你看下面的话应该很容易明白,如果不懂,先了解下MVC和类吧
M就是模型,自定义模型其实很简单,在开发中其实大部分的东西都可以抽象为模型,每个模型可以有很多属性(字段),那么只要在模型中,可以动态的处理字段就好(比如:文本字段,选择字段,图片字段,编辑器字段),只要创建好模型后,集成公用的基础类和基础方法,大部分的内容都可以解决了
C:就是控制器,在继承了公用控制器后(方法随你,比如模板解析之类的方法),如果在业务上还有其他需求,那么就在当前类控制器中增加相应的方法
V:就是视图了,视图其实就是前台显示,也可以理解为模板。
只要有一个基础类,剩下的继承上一层,这样可以做到耦合降低。
比如:核心类 —— 前台类, 后台类 —— 前台自定义模型产生的类,后台自定义模型产生的类。
下级的,下级只依赖上级,上级与下级无耦合,同级之间无耦合。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
