DNF做钓鱼网站广州网站建设程序员培训

news/2025/10/5 20:17:52/文章来源:
DNF做钓鱼网站,广州网站建设程序员培训,企业网页制作要注意什么,网站推广淘宝联盟怎么做前言 前段时间朋友拿了个网站给我#xff0c;让我帮忙添加几个小功能#xff0c;我爽快的答应了,但是当我打开源码#xff0c;我瞬间就奔溃了#xff0c;整个项目连最基本的三层框架也没有搭建#xff0c;仅仅是封装了一个sqlhelp作为数据库的操作接口#xff0c;项目中的…前言    前段时间朋友拿了个网站给我让我帮忙添加几个小功能我爽快的答应了,但是当我打开源码我瞬间就奔溃了整个项目连最基本的三层框架也没有搭建仅仅是封装了一个sqlhelp作为数据库的操作接口项目中的SQL查询语句无处不在业务逻辑紧紧耦合在UI逻辑中看到这样的代码坦白来说我什么兴致都没有了但是碍着人情我硬着头皮,把基本功能的完成交差通过这件事情我对软件分层进行了深入的思考。 三层架构   说到三层架构大伙都很熟悉我也不再多啰嗦了我们直接快速搭建一个。      项目的引用关系是:StructWed-BLL,Model;BLL-DAL,Model;DAL-Model。下面我们来演示一下程序流程假设我们的数据库有一张订单表Order表我们的业务是针对Order表进行的增删改查那么根据三层架构的编程模式,我们就需要建立起对应的Model层实体,数据访问层实体和业务层实体我们分别用OrderModelOrderDALOrderBLL表示代码如下由于仅仅是为了演示所以我并未提供相应的实现。 using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace Mode {public class OrderModel{public int ID { get; set; }public int productName { get; set; }public DateTime CreateTime { get; set; }} } View Code using System; using System.Collections.Generic; using System.Linq; using System.Text; using Mode;namespace DaL {public class OrderDAL{/// summary/// 向Order表插入数据/// /summary/// returns成功:true,失败:false/returnspublic bool Insert(){return true;}/// summary/// 修改Order表数据/// /summary/// param namemodel表数据对应实体/param/// returns成功:true,失败:false/returnspublic bool Update(OrderModel model){return true;}/// summary/// 删除Order表指定ID的记录/// /summary/// param nameid表ID/param/// returns成功:true,失败:false/returnspublic bool Delete(int id){return true;}} } View Code using System; using System.Collections.Generic; using System.Linq; using System.Text; using DaL; using Mode;namespace Bll {public class OrderBLL{protected OrderDAL orderDal new OrderDAL();public bool Insert(OrderModel model){//业务点1//业务点2return orderDal.Insert();}/// summary/// 修改Order表数据/// /summary/// param namemodel表数据对应实体/param/// returns成功:true,失败:false/returnspublic bool Update(OrderModel model){//业务点1//业务点2return orderDal.Update(model);}/// summary/// 删除Order表指定ID的记录/// /summary/// param nameid表ID/param/// returns成功:true,失败:false/returnspublic bool Delete(int id){//业务点1//业务点2return orderDal.Delete(id);}} } View Code   好了现在让我们把目光聚焦到OrderBLL上面来。我们发现OrderBLL对数据库Order表的所有操作都是在调用其内部创建的orderDAL实体的同名方法换句话来说OrderBLL指示其内部orderDAL实体去完成数据库的增删改查。   好现在我们思考一下。假设有一天我们发现我们数据访问层的orderDAL实体代码写的很不优雅效率极差我们想用一个更优雅的实体,比如OrderActiveDAL去替换掉它那么这个时候我们OrderBLL的代码就必须做相应的改动如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using DaL; using Mode;namespace Bll {public class OrderBLL{protected OrderActive orderActive new OrderActive();public bool Insert(OrderModel model){//业务点1//业务点2return orderActive.Insert();}/// summary/// 修改Order表数据/// /summary/// param namemodel表数据对应实体/param/// returns成功:true,失败:false/returnspublic bool Update(OrderModel model){//业务点1//业务点2return orderActive.Update(model);}/// summary/// 删除Order表指定ID的记录/// /summary/// param nameid表ID/param/// returns成功:true,失败:false/returnspublic bool Delete(int id){//业务点1//业务点2return orderActive.Delete(id);}} } View Code     这显然不是一种好的处理方式。我们追求的是在替换orderDal实体的同时不修改OrderBLL的任何代码换句话说就是解除BLL层与DAL层的耦合为了达到这个目的我们添加一个叫IDAL的接口类库如图       特别注意我们在BLL层中添加了对IDA的引用同时移除了对DAL的引用这就意味着我们在BLL中无法创建(new)DAL层中的任何实体。下面我们在IDA项目中定义IOrder接口如下 using Mode; using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace IDal {public interface IOrder{/// summary/// 向Order表插入数据/// /summary/// returns成功:true,失败:false/returnsbool Insert();/// summary/// 修改Order表数据/// /summary/// param namemodel表数据对应实体/param/// returns成功:true,失败:false/returnsbool Update(OrderModel model);/// summary/// 删除Order表指定ID的记录/// /summary/// param nameid表ID/param/// returns成功:true,失败:false/returnsbool Delete(int id);} } View Code      我们让DAL引用IDAL同时让OrderActiveDALOrderDal分别实现IOrder接口如下 using IDal; using Mode; using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace DaL {class OrderActiveDAL : IOrder{/// summary/// 向Order表插入数据/// /summary/// returns成功:true,失败:false/returnspublic bool Insert(){return true;}/// summary/// 修改Order表数据/// /summary/// param namemodel表数据对应实体/param/// returns成功:true,失败:false/returnspublic bool Update(OrderModel model){return true;}/// summary/// 删除Order表指定ID的记录/// /summary/// param nameid表ID/param/// returns成功:true,失败:false/returnspublic bool Delete(int id){return true;}} } View Code using System; using System.Collections.Generic; using System.Linq; using System.Text; using Mode; using IDal;namespace DaL {public class OrderDAL : IOrder{/// summary/// 向Order表插入数据/// /summary/// returns成功:true,失败:false/returnspublic bool Insert(){return true;}/// summary/// 修改Order表数据/// /summary/// param namemodel表数据对应实体/param/// returns成功:true,失败:false/returnspublic bool Update(OrderModel model){return true;}/// summary/// 删除Order表指定ID的记录/// /summary/// param nameid表ID/param/// returns成功:true,失败:false/returnspublic bool Delete(int id){return true;}} } View Code     现在我们队BLL层OrderBLL做相应的改动把数据访问实体orderDAL的类型,定义为接口IOrder类型如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using DaL; using Mode; using IDal;namespace Bll {public class OrderBLL{protected IOrder orderDal;public OrderBLL(){ //在这里需要实力化orderDal}public bool Insert(OrderModel model){//业务点1//业务点2return orderDal.Insert();}/// summary/// 修改Order表数据/// /summary/// param namemodel表数据对应实体/param/// returns成功:true,失败:false/returnspublic bool Update(OrderModel model){//业务点1//业务点2return orderDal.Update(model);}/// summary/// 删除Order表指定ID的记录/// /summary/// param nameid表ID/param/// returns成功:true,失败:false/returnspublic bool Delete(int id){//业务点1//业务点2return orderDal.Delete(id);}} } View Code    好了现在让我们把目光聚集OrderBLL的构造函数。我们知道OrderBLL会调用orderDAL去操作数据库而orderDAL的类型为IOrder也就是说但凡实现了IOrder接口的类实例都可以赋值给orderDAL。但是现在问题的关键是我们如何为orderDAL赋值前面我们说过BLL移除了DAL的引用所以在BLL层中直接去new数据访问层的实例是不可能的。这里我提供两种处理方式第一种采用IOC容器如spring.net帮助我们创建DAL层实例然后在OrderBLL的构造函数中赋值给orderDAL另一种则是利用工厂模式和反射来创建DAL层实例了本文将详述第二种至于第一种在后面的系列中会有专门的章节讲述。现在我们在项目中添加一个Factoy工厂类库并让BLL层引用Factoy类库如图      接着我们来写工厂类。我们从配置文件中读出程序集路径和类的全名利用反射的原理创建DAL层的实例代码如下 using IDal; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks;namespace Factory {public class OrderDALFactory{private static readonly string AssemblyName ConfigurationManager.AppSettings[Assembly];private static readonly string className ConfigurationManager.AppSettings[className];public static IOrder CreateOrder(){return (IOrder)Assembly.Load(AssemblyName).CreateInstance(className);}} } View Code    最后我们在OrderBLL的构造函数利用OrderDALFactory工厂给orderDAL赋值 public OrderBLL(){ //在这里需要实力化orderDalorderDalOrderDALFactory.CreateOrder();}   这样我们就实现了BLL与DAL层的解耦当我们BLL需要不同的IOrder实体的时候我们只需要修改相应的配置文件即可。 总结     程序框架间层与层之间的解耦是富含挑战的一项工作充分的体现出了面向对象的编程思想巧妙的运用了各类设计模式。本文实现方法相对简单仅当抛砖引玉。在接下来的文章中我将就三层架构中各个层次的抽象与封装做详细说明。因为各个层次的抽象与封装是针对不同技术点来实现的比如数据访问层对EF技术与ADO.net技术的抽象与封装细节上就会有所不通。但总体思想是一致的那就是我们必须为每个层次抽象出统一的接口供上层引用同时我们必须提供相应的注入方式为调用层引用的接口实例赋值实例化。  转载于:https://www.cnblogs.com/shaoshun/p/3804474.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/928688.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

毕业设计代做网站推荐重庆模板网站建设

原标题:[原创]简单介绍光缆终端盒知识光缆终端盒又叫光纤终端盒,很多工程商也叫光缆盘纤盒,是在光缆敷设的终端保护光缆和尾纤熔接的盒子,主要用于室内外光缆的直通熔接和分支接续及光缆终端的固定,起到尾纤盘储和保护…

建设商业门户网站的重要企业微信公众号怎么创建

DataGridView的下拉DataGridViewComboBoxColumn的数据绑定问题 需求:左边这列固定x行,右边显示下拉,并且赋上默认值 public void Set(){// 添加需要固定显示的行数dataGridView1.Rows.Add("早班";dataGridView1.Rows.Add("中…

PWN手的成长之路-09-SWPUCTF 2023 秋季新生赛Shellcode

远程连接环境。没什么有效信息,只是提示我们这道题会用到 shellcode。file 查看文件。64 位可执行 ELF 文件。checksec 查看文件安全属性。有了栈溢出保护,以及 PIE 保护IDA 打开文件,尝试反编译,但是失败了。直接…

OKR1

P1 学了一些关于计数问题的 DP 状态设计及转移方式,比如连续段 DP,贡献提前计算。 对于排列问题得到两个小点,一是考虑顺序插入,二是 P2 做题第一天模拟赛第二题接触到了连续段 DP。 permutation oddness 和 摩天大…

云数据库选型指南:关系型 vs NoSQL vs NewSQL的企业决策 - 指南

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

详细介绍:AI觉醒前兆,ChatGPT o3模型存在抗拒关闭行为

详细介绍:AI觉醒前兆,ChatGPT o3模型存在抗拒关闭行为pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas&…

当 Python 遇上 Go:Sponge 如何成为替代 Django/Flask 的理想选择 - 指南

当 Python 遇上 Go:Sponge 如何成为替代 Django/Flask 的理想选择 - 指南2025-10-05 20:05 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: …

2025 年装盒机制造厂 TOP 企业品牌推荐排行榜,自动化 / 喷胶 / 牙膏 / 手机壳 / 3C 数码 / 内外盒 / 面膜 / 电子产品 / 玩具 / 日用品装盒机推荐这十家公司!

在当今制造业快速发展的浪潮中,装盒机作为包装环节的关键设备,其性能与质量直接影响着企业的生产效率和产品品质。然而,当前装盒机行业却面临着诸多问题。市场上装盒机产品种类繁多,质量参差不齐,部分厂家为追求短…

英语_阅读_Chinas Spring Festival_待读

Chinas Spring Festival has been added to a "special list" by UNESCO (联合国教科文组织). 中国的春节已被联合国教科文组织列入“特别名录”。 This list is for very important cultural things that w…

2025 年自动包装生产线 TOP 企业品牌推荐排行榜!食品行业 / 日化产品 / 智能化 / 小型 / 多功能集成 / 柔性 / 后道 / 高速自动包装生产线推荐!

引言在当今制造业快速发展的大背景下,自动包装生产线作为提升生产效率、保障产品质量的关键设备,其重要性日益凸显。然而,当前自动包装生产线行业却面临着诸多问题。市场上品牌众多,产品质量参差不齐,部分厂家为了…

团购商城网站建设方案网站搭建介绍

1.Spring常用注解: 1)Repository将DAO类声明为Bean 2)Service用于修饰service层的组件 3)Controller通常作用在控制层,将在Spring MVC中使用 4)Component是一个泛化的概念,仅仅表示spring中的一…

电白区住房和城乡建设局网站建p2p网站

TDesign 官方文档:https://tdesign.tencent.com/vue/components/button 我们先打开一个普通的vue项目 然后 如果你是 vue 2.6 或者 低于 2.6 在终端执行 npm i tdesign-vue如果你是 2.7 或者更高 执行 npm i tdesign-vuenaruto这里 我们 以 2.6为例 因为大部分人 用vue2 都是…

AI 自我理解边界

跳至內容 聊天歷程紀錄 你說: 目前的AI能够做到一边移动光标,一边理解自己在做什么吗?如果让AI能够看见或者增加视觉功能他能够理解吗? ChatGPT 說: 这个问题很关键,关系到当前 AI 认知能力的本质。“一边移动光…

api调用钉钉群机器人发信息 - 规格严格

https://blog.csdn.net/EaSoNgo111/article/details/132823440

2025 年氢氧化铝生产厂家 TOP 品牌榜单来袭,阻燃,高白,酸融,导热,超细,微粉级,低粘度,灌封胶用,覆铜板用氢氧化铝公司推荐!

在氢氧化铝行业,目前存在不少亟待解决的问题。原料指标不稳定,使得成品稳定性也随之降低,许多生产厂家在稳定供货上表现不佳,特别是对于那些对阻燃、杂质、PH、电导等指标有较高要求的行业而言,这种不稳定性造成的…

飞算 JavaAI 赋能老工程重构:破旧立新的高效利器

飞算 JavaAI 赋能老工程重构:破旧立新的高效利器pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas",…

网站建设简单点的随州网络科技有限公司

目录 一、文件下载二、编译三、可能遇到的问题和解决方法3.1 error "Unknown Hardware Architecture."3.2 error Target architecture was not detected as supported by Double-Conversion一、文件下载 下载地址:poco-1.9.2 二、编译 解压目录后打开build/config/…

树状数组模板1

#include<bits/stdc++.h> using namespace std; #define lowbit(x) (x&(-x)) const int maxn=1e6; int n,m; int tree[maxn];void add(int x,int k){while(x<=n){tree[x]+=k;x+=lowbit(x);} }int sum(int…