Chapter 4.开放-封闭原则

本文探讨了开放-封闭原则的核心概念及其在软件设计中的实施方式,强调了如何通过构造抽象来隔离变化,避免修改现有代码,以及拒绝不成熟的抽象的重要性。通过实例分析,展示了如何遵循此原则来提高代码的可维护性和可扩展性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开放-封闭原则:是说软件实体应该可以扩展,但不可修改。

设计人员必须对于他设计的模块应该对哪种变化封闭做出选择,先猜测出最有可能发生的变化种类,然后构造抽象来隔离那些变化。

面对需求,对程序的改动是通过增加新代码进行的,而不是更改现有的代码。

拒绝不成熟的抽象和抽象本身一样重要。

转载于:https://www.cnblogs.com/tuifeideyouran/p/3732847.html

model Unnamed11 ThermalSystems.HeatExchangers.FinAndTube.MoistAirLiquid.CrossFlowHX crossFlowHX( liquidType=sim.liquidType1, gasType=sim.gasType1, redeclare model TubeSideHeatTransferModel = ThermalSystems.HeatExchangers.FinAndTube.TransportPhenomena.TubeSideHeatTransfer.GnielinskiDittusBoelter, redeclare model FinSideHeatTransferModel = ThermalSystems.HeatExchangers.FinAndTube.TransportPhenomena.FinSideHeatTransfer.Haaf) annotation (Placement(transformation(extent={{-14,-2},{14,26}}))); inner ThermalSystems.SystemInformationManager sim(redeclare TSMedia.GasTypes.TSMedia_MoistAir gasType1, redeclare TSMedia.LiquidTypes.TSMedia_Water liquidType1) annotation (Placement(transformation(extent={{80,78},{100,98}}))); ThermalSystems.LiquidComponents.JunctionElements.VolumeJunction junction( TInitial=298.15) annotation (Placement(transformation( extent={{-4,-4},{4,4}}, rotation=90, origin={-50,0}))); ThermalSystems.HeatExchangers.FinAndTube.MoistAirLiquid.CrossFlowHX crossFlowHX1( liquidType=sim.liquidType1, gasType=sim.gasType1, redeclare model TubeSideHeatTransferModel = ThermalSystems.HeatExchangers.FinAndTube.TransportPhenomena.TubeSideHeatTransfer.GnielinskiDittusBoelter, redeclare model FinSideHeatTransferModel = ThermalSystems.HeatExchangers.FinAndTube.TransportPhenomena.FinSideHeatTransfer.Haaf) annotation (Placement(transformation(extent={{-14,-66},{14,-38}}))); ThermalSystems.LiquidComponents.Boundaries.Boundary boundary(boundaryType="p") annotation (Placement(transformation(extent={{28,-62},{36,-42}}))); ThermalSystems.LiquidComponents.Boundaries.Boundary boundary1(boundaryType="p") annotation (Placement(transformation(extent={{32,0},{40,20}}))); ThermalSystems.LiquidComponents.Boundaries.Boundary boundary2( liquidType=sim.liquidType1, boundaryType="m_flow", m_flowFixed=-2000, V_flowFixed=-2) annotation (Placement(transformation(extent={{-82,-10},{-74,10}}))); ThermalSystems.GasComponents.Boundaries.Boundary boundary3(boundaryType="V_flow", V_flowFixed=-3.6) annotation (Placement(transformation(extent={{56,28},{64,48}}))); ThermalSystems.GasComponents.Boundaries.Boundary boundary4(boundaryType="V_flow", V_flowFixed=-3.6) annotation (Placement(transformation(extent={{64,8},{72,28}}))); ThermalSystems.GasComponents.Boundaries.Boundary boundary5(boundaryType="p") annotation (Placement(transformation(extent={{32,-28},{40,-8}}))); ThermalSystems.GasComponents.Boundaries.Boundary boundary6(boundaryType="p") annotation (Placement(transformation(extent={{34,-88},{42,-68}}))); equation connect(junction.portC, crossFlowHX.portA_liq) annotation (Line( points={{-50,4},{-50,12},{-14,12}}, color={0,170,238}, thickness=0.5)); connect(junction.portB, crossFlowHX1.portA_liq) annotation (Line( points={{-50,-4},{-50,-52},{-14,-52}}, color={0,170,238}, thickness=0.5)); connect(crossFlowHX1.portB_liq, boundary.port) annotation (Line( points={{14,-52},{32,-52}}, color={0,170,238}, thickness=0.5)); connect(boundary1.port, crossFlowHX.portB_liq) annotation (Line( points={{36,10},{36,12},{14,12}}, color={0,170,238}, thickness=0.5)); connect(boundary2.port, junction.portA) annotation (Line( points={{-78,0},{-66,0},{-66,2.22045e-16},{-54,2.22045e-16}}, color={0,170,238}, thickness=0.5)); connect(boundary4.port, crossFlowHX1.portA_gas) annotation (Line( points={{68,18},{76,18},{76,-32},{0,-32},{0,-38}}, color={255,153,0}, thickness=0.5)); connect(boundary3.port, crossFlowHX.portA_gas) annotation (Line( points={{60,38},{0,38},{0,26}}, color={255,153,0}, thickness=0.5)); connect(crossFlowHX.portB_gas, boundary5.port) annotation (Line( points={{0,-2},{0,-18},{36,-18}}, color={255,153,0}, thickness=0.5)); connect(crossFlowHX1.portB_gas, boundary6.port) annotation (Line( points={{0,-66},{0,-78},{38,-78}}, color={255,153,0}, thickness=0.5)); annotation (uses( ThermalSystems(version="1.10.0"), TSMedia(version="1.10.0"), Modelica(version="4.0.0"))); end Unnamed11; 在dymola中运行这段代码后报错Translation of Unnamed11: The problem is structurally singular. It has 1722 scalar unknowns and 1722 scalar equations. The Real part has 1722 unknowns and 1722 equations. The Integer part has 0 unknowns and 0 equations. The Boolean part has 0 unknowns and 0 equations. The String part has 0 unknowns and 0 equations. Attempting to further localize singularity. The model Unnamed11 is structurally singular. The model includes the following hints: A liquid mass flow rate cannot be uniquely calculated. The reason could be that - a hydraulic capacitor object (ThermalSystems.LiquidComponents.HydraulicCapacitor) or - a liquid boundary type "p" is missing, to define the pressure inside a liquid circuit, or - a connector of a liquid component is not connected. The problem is structurally singular for the element type Real. Translation aborted. WARNINGS have been issued. ERRORS have been issued. 请问是什么问题,该如何解决
08-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值