{"id":4329,"date":"2025-08-20T11:07:42","date_gmt":"2025-08-20T03:07:42","guid":{"rendered":"https:\/\/www.caiqinyi.cn\/?p=4329"},"modified":"2025-08-20T11:10:39","modified_gmt":"2025-08-20T03:10:39","slug":"ue5_design_pattern_bridge_pattern","status":"publish","type":"post","link":"https:\/\/www.caiqinyi.cn\/index.php\/2025\/08\/20\/ue5_design_pattern_bridge_pattern\/","title":{"rendered":"[UE5 \u8bbe\u8ba1\u6a21\u5f0f] \u6865\u63a5\u6a21\u5f0fBridge Pattern"},"content":{"rendered":"<p><script type=\"text\/javascript\" async src=\"https:\/\/www.caiqinyi.cn\/wp-content\/MathJax\/MathJax.js?config=TeX-AMS_CHTML\">\n<\/script><br \/>\n<script type=\"text\/x-mathjax-config\">\n    MathJax.Hub.Config({\n        tex2jax: {inlineMath: [['$','$']]},\n        TeX: {equationNumbers: {autoNumber: [\"AMS\"], useLabelIds: true}},\n        \"HTML-CSS\": {linebreaks: {automatic: true}},\n        SVG: {linebreaks: {automatic: true}}\n    });\n<\/script><\/p>\n<p><strong>\u53c2\u8003\u6750\u6599<\/strong><br \/>\n1. <a href=\"https:\/\/www.cnblogs.com\/shiroe\/p\/14909707.html\">\u3010UE4 \u8bbe\u8ba1\u6a21\u5f0f\u3011\u7b56\u7565\u6a21\u5f0f Strategy Pattern<\/a><br \/>\n2. <a href=\"https:\/\/www.runoob.com\/design-pattern\/bridge-pattern.html\">\u6865\u63a5\u6a21\u5f0f<\/a><br \/>\n3. <a href=\"https:\/\/blog.csdn.net\/2302_80644606\/article\/details\/141462784\">\u6e38\u620f\u5f00\u53d1\u8bbe\u8ba1\u6a21\u5f0f\u4e4b\u6865\u63a5\u6a21\u5f0f<\/a><\/p>\n<p><strong>1. \u6982\u8ff0<\/strong><\/p>\n<p><strong>1.1 \u63cf\u8ff0<\/strong><\/p>\n<p>$\\cdot$ \u6865\u63a5(Bridge) \u662f\u7528\u4e8e\u628a\u62bd\u8c61\u5316\u4e0e\u5b9e\u73b0\u5316\u89e3\u8026, \u4f7f\u5f97\u4e8c\u8005\u53ef\u4ee5\u72ec\u7acb\u53d8\u5316. \u8fd9\u79cd\u7c7b\u578b\u7684\u8bbe\u8ba1\u6a21\u5f0f\u5c5e\u4e8e\u7ed3\u6784\u578b\u6a21\u5f0f, \u5b83\u901a\u8fc7\u63d0\u4f9b\u62bd\u8c61\u5316\u548c\u5b9e\u73b0\u5316\u4e4b\u95f4\u7684\u6865\u63a5\u7ed3\u6784, \u6765\u5b9e\u73b0\u4e8c\u8005\u7684\u89e3\u8026.<br \/>\n$\\\\$ \u8fd9\u79cd\u6a21\u5f0f\u6d89\u53ca\u5230\u4e00\u4e2a\u4f5c\u4e3a\u6865\u63a5\u7684\u63a5\u53e3, \u4f7f\u5f97\u5b9e\u4f53\u7c7b\u7684\u529f\u80fd\u72ec\u7acb\u4e8e\u63a5\u53e3\u5b9e\u73b0\u7c7b, \u8fd9\u4e24\u79cd\u7c7b\u578b\u7684\u7c7b\u53ef\u88ab\u7ed3\u6784\u5316\u6539\u53d8\u800c\u4e92\u4e0d\u5f71\u54cd.<br \/>\n$\\\\$ \u6865\u63a5\u6a21\u5f0f\u7684\u76ee\u7684\u662f\u5c06\u62bd\u8c61\u4e0e\u5b9e\u73b0\u5206\u79bb, \u4f7f\u5b83\u4eec\u53ef\u4ee5\u72ec\u7acb\u5730\u53d8\u5316, \u8be5\u6a21\u5f0f\u901a\u8fc7\u5c06\u4e00\u4e2a\u5bf9\u8c61\u7684\u62bd\u8c61\u90e8\u5206\u4e0e\u5b83\u7684\u5b9e\u73b0\u90e8\u5206\u5206\u79bb, \u4f7f\u5b83\u4eec\u53ef\u4ee5\u72ec\u7acb\u5730\u6539\u53d8. \u5b83\u901a\u8fc7\u7ec4\u5408\u7684\u65b9\u5f0f, \u800c\u4e0d\u662f\u7ee7\u627f\u7684\u65b9\u5f0f, \u5c06\u62bd\u8c61\u548c\u5b9e\u73b0\u7684\u90e8\u5206\u8fde\u63a5\u8d77\u6765.<\/p>\n<p><!--more--><\/p>\n<p><strong>1.2 \u5957\u8def<\/strong><\/p>\n<p>$\\cdot$ <strong>\u5b9e\u73b0\u65b9\u5f0f:<\/strong><br \/>\n$\\\\$ 1) \u5206\u79bb\u591a\u89d2\u5ea6\u5206\u7c7b: \u5c06\u4e0d\u540c\u89d2\u5ea6\u7684\u5206\u7c7b\u903b\u8f91\u5206\u79bb, \u5141\u8bb8\u5b83\u4eec\u72ec\u7acb\u53d8\u5316.<br \/>\n$\\\\$ 2) \u51cf\u5c11\u8026\u5408: \u964d\u4f4e\u62bd\u8c61\u4e0e\u5b9e\u73b0\u4e4b\u95f4\u7684\u8026\u5408\u5ea6.<\/p>\n<p>$\\cdot$ <strong>\u5173\u952e\u4ee3\u7801:<\/strong><br \/>\n$\\\\$ 1) \u62bd\u8c61\u7c7b: \u5b9a\u4e49\u4e00\u4e2a\u62bd\u8c61\u7c7b, \u4f5c\u4e3a\u7cfb\u7edf\u7684\u4e00\u90e8\u5206.<br \/>\n$\\\\$ 2) \u5b9e\u73b0\u7c7b: \u5b9a\u4e49\u4e00\u4e2a\u6216\u591a\u4e2a\u5b9e\u73b0\u7c7b, \u4e0e\u62bd\u8c61\u7c7b\u901a\u8fc7\u805a\u5408(\u800c\u975e\u7ee7\u627f) \u5173\u8054.<\/p>\n<p>$\\cdot$ <strong>\u7ed3\u6784:<\/strong><br \/>\n$\\\\$ \u4ee5\u4e0b\u662f\u6865\u63a5\u6a21\u5f0f\u7684\u51e0\u4e2a\u5173\u952e\u89d2\u8272:<br \/>\n$\\\\$ 1) \u62bd\u8c61(Abstraction): \u5b9a\u4e49\u62bd\u8c61\u63a5\u53e3, \u901a\u5e38\u5305\u542b\u5bf9\u5b9e\u73b0\u63a5\u53e3\u7684\u5f15\u7528.<br \/>\n$\\\\$ 2) \u6269\u5c55\u62bd\u8c61(Refined Abstraction): \u5bf9\u62bd\u8c61\u7684\u6269\u5c55, \u53ef\u4ee5\u662f\u62bd\u8c61\u7c7b\u7684\u5b50\u7c7b\u6216\u5177\u4f53\u5b9e\u73b0\u7c7b.<br \/>\n$\\\\$ 3) \u5b9e\u73b0(Implementor): \u5b9a\u4e49\u5b9e\u73b0\u63a5\u53e3, \u63d0\u4f9b\u57fa\u672c\u64cd\u4f5c\u7684\u63a5\u53e3.<br \/>\n$\\\\$ 4) \u5177\u4f53\u5b9e\u73b0(Concrete Implementor): \u5b9e\u73b0\u5b9e\u73b0\u63a5\u53e3\u7684\u5177\u4f53\u7c7b.<\/p>\n<p><strong>1.3 \u4f7f\u7528\u573a\u666f<\/strong><\/p>\n<p>$\\cdot$ \u5f53\u7cfb\u7edf\u53ef\u80fd\u4ece\u591a\u4e2a\u89d2\u5ea6\u8fdb\u884c\u5206\u7c7b, \u4e14\u6bcf\u4e2a\u89d2\u5ea6\u90fd\u53ef\u80fd\u72ec\u7acb\u53d8\u5316\u65f6, \u6865\u63a5\u6a21\u5f0f\u662f\u5408\u9002\u7684.<\/p>\n<p><strong>1.4 \u4f18\u7f3a\u70b9<\/strong><\/p>\n<p>$\\cdot$ <strong>\u4f18\u70b9:<\/strong><br \/>\n$\\\\$ 1) \u62bd\u8c61\u4e0e\u5b9e\u73b0\u5206\u79bb: \u63d0\u9ad8\u4e86\u7cfb\u7edf\u7684\u7075\u6d3b\u6027\u548c\u53ef\u7ef4\u62a4\u6027.<br \/>\n$\\\\$ 2) \u6269\u5c55\u80fd\u529b\u5f3a: \u53ef\u4ee5\u72ec\u7acb\u5730\u6269\u5c55\u62bd\u8c61\u548c\u5b9e\u73b0.<br \/>\n$\\\\$ 3) \u5b9e\u73b0\u7ec6\u8282\u900f\u660e: \u7528\u6237\u4e0d\u9700\u8981\u4e86\u89e3\u5b9e\u73b0\u7ec6\u8282.<\/p>\n<p>$\\cdot$ <strong>\u7f3a\u70b9:<\/strong><br \/>\n$\\\\$ 1) \u7406\u89e3\u4e0e\u8bbe\u8ba1\u96be\u5ea6: \u6865\u63a5\u6a21\u5f0f\u589e\u52a0\u4e86\u7cfb\u7edf\u7684\u7406\u89e3\u4e0e\u8bbe\u8ba1\u96be\u5ea6.<br \/>\n$\\\\$ 2) \u805a\u5408\u5173\u8054: \u8981\u6c42\u5f00\u53d1\u8005\u5728\u62bd\u8c61\u5c42\u8fdb\u884c\u8bbe\u8ba1\u4e0e\u7f16\u7a0b.<\/p>\n<p><strong>2. UE5\u5b9e\u8df5<\/strong><\/p>\n<p>\u6211\u4eec\u6709\u4e00\u4e2a\u4f5c\u4e3a\u6865\u63a5\u5b9e\u73b0\u7684DrawAPI\u63a5\u53e3\u548c\u5b9e\u73b0\u4e86DrawAPI\u63a5\u53e3\u7684\u5b9e\u4f53\u7c7bRedCircle, GreenCircle. Shape\u662f\u4e00\u4e2a\u62bd\u8c61\u7c7b, \u5c06\u4f7f\u7528DrawAPI\u7684\u5bf9\u8c61. BridgePatternDemo\u7c7b\u4f7f\u7528Shape\u7c7b\u6765\u753b\u51fa\u4e0d\u540c\u989c\u8272\u7684\u5706.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.caiqinyi.cn\/wp-content\/uploads\/2025\/08\/20201015-bridge.png\" alt=\"\" width=\"760\" height=\"470\" class=\"aligncenter size-full wp-image-4334\" srcset=\"https:\/\/www.caiqinyi.cn\/wp-content\/uploads\/2025\/08\/20201015-bridge.png 760w, https:\/\/www.caiqinyi.cn\/wp-content\/uploads\/2025\/08\/20201015-bridge-300x186.png 300w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><\/p>\n<p><strong>2.1 \u6b65\u9aa41<\/strong><\/p>\n<p>\u521b\u5efa\u6865\u63a5\u5b9e\u73b0\u63a5\u53e3.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"C++\" data-enlighter-theme=\"monokai\">\r\n\r\n#pragma once\r\n\r\n\r\nclass FDrawAPI\r\n{\r\npublic:\r\n\tvoid DrawCircle(int32 Radius, int32 X, int32 Y)\r\n\t{\r\n\t}\r\n};\r\n\r\n<\/pre>\n<p><strong>2.2 \u6b65\u9aa42<\/strong><\/p>\n<p>\u521b\u5efa\u5b9e\u73b0\u4e86<em>FDrawAPI<\/em>\u63a5\u53e3\u7684\u5b9e\u4f53\u6865\u63a5\u5b9e\u73b0\u7c7b.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"C++\" data-enlighter-theme=\"monokai\">\r\n\r\n#pragma once\r\n\r\n#include \"DrawAPI.h\"\r\n#include \"CoreMinimal.h\"\r\n\r\n\r\nclass FRedCircle final : public FDrawAPI\r\n{\r\npublic:\r\n\tvirtual void DrawCircle(int32 Radius, int32 X, int32 Y)\r\n\t{\r\n\t\tUE_LOG(LogTemp, Log, TEXT(\"Drawing Circle[ color: red, radius: %d, x: %d, %d]\"), Radius, X, Y);\r\n\t}\r\n};\r\n\r\n<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"C++\" data-enlighter-theme=\"monokai\">\r\n\r\n#pragma once\r\n\r\n#include \"DrawAPI.h\"\r\n#include \"CoreMinimal.h\"\r\n\r\n\r\nclass FGreenCircle final : public FDrawAPI\r\n{\r\npublic:\r\n\tvirtual void DrawCircle(int32 Radius, int32 X, int32 Y)\r\n\t{\r\n\t\tUE_LOG(LogTemp, Log, TEXT(\"Drawing Circle[ color: green, radius: %d, x: %d, %d]\"), Radius, X, Y);\r\n\t}\r\n};\r\n\r\n<\/pre>\n<p><strong>2.3 \u6b65\u9aa43<\/strong><\/p>\n<p>\u4f7f\u7528FDrawAPI\u63a5\u53e3\u521b\u5efa\u62bd\u8c61\u7c7bShape.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"C++\" data-enlighter-theme=\"monokai\">\r\n\r\n#pragma once\r\n\r\n#include \"DrawAPI.h\"\r\n#include \"CoreMinimal.h\"\r\n\r\n\r\nclass FShape\r\n{\r\npublic:\r\n\tvirtual void Draw() = 0;\r\n\r\nprotected:\r\n\tFShape(FDrawAPI& InDrawAPI) : DrawAPI(MoveTemp(InDrawAPI))\r\n\t{\r\n\t}\r\n\r\nprotected:\r\n\tFDrawAPI DrawAPI;\r\n};\r\n\r\n<\/pre>\n<p><strong>2.4 \u6b65\u9aa44<\/strong><\/p>\n<p>\u521b\u5efa\u5b9e\u73b0\u4e86Shape\u62bd\u8c61\u7c7b\u7684\u5b9e\u4f53\u7c7b.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"C++\" data-enlighter-theme=\"monokai\">\r\n\r\n#pragma once\r\n\r\n#include \"Shape.h\"\r\n\r\n\r\nclass FCircle final : public FShape\r\n{\r\npublic:\r\n\tFCircle(int32 InX, int32 InY, int32 InRadius, FDrawAPI& DrawAPI) : Super(DrawAPI), X(InX), Y(InY), Radius(InRadius)\r\n\t{\r\n\t}\r\n\r\n\tvoid Draw()\r\n\t{\r\n\t\tDrawAPI.DrawCircle(Radius, X, Y);\r\n\t}\r\n\r\nprivate:\r\n\tint32 X;\r\n\r\n\tint32 Y;\r\n\r\n\tint32 Radius;\r\n};\r\n\r\n<\/pre>\n<p><strong>2.5 \u6b65\u9aa45<\/strong><\/p>\n<p>\u4f7f\u7528FShape\u548cFDrawAPI\u7c7b\u753b\u51fa\u4e0d\u540c\u989c\u8272\u7684\u5706.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"C++\" data-enlighter-theme=\"monokai\">\r\n\r\n#include \"RedCircle.h\"\r\n#include \"GreenCircle.h\"\r\n#include \"Circle.h\"\r\n\r\n\r\nint main(int argc, char* argv[]) \r\n{\r\n\tFShape* RedCircleShape = new FCircle(100, 100, 10, RedCircle());\r\n\tFShape* GreenCircleShape = new FCircle(100, 100, 10, GreenCircle());\r\n\r\n\tRedCircleShape->Draw();\r\n\tGreenCircleShape->Draw();\r\n\r\n\tdelete RedCircleShape;\r\n\tRedCircleShape = nullptr;\r\n\r\n\tdelete GreenCircleShape;\r\n\tGreenCircleShape = nullptr;\r\n\r\n\treturn 0;\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\u6750\u6599 1. \u3010UE4 \u8bbe\u8ba1\u6a21\u5f0f\u3011\u7b56\u7565\u6a21\u5f0f Strategy Pattern 2. \u6865\u63a5\u6a21\u5f0f 3. \u6e38\u620f\u5f00\u53d1 &hellip; <a href=\"https:\/\/www.caiqinyi.cn\/index.php\/2025\/08\/20\/ue5_design_pattern_bridge_pattern\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">[UE5 \u8bbe\u8ba1\u6a21\u5f0f] \u6865\u63a5\u6a21\u5f0fBridge Pattern<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,32],"tags":[],"_links":{"self":[{"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/4329"}],"collection":[{"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/comments?post=4329"}],"version-history":[{"count":7,"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/4329\/revisions"}],"predecessor-version":[{"id":4338,"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/4329\/revisions\/4338"}],"wp:attachment":[{"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/media?parent=4329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/categories?post=4329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.caiqinyi.cn\/index.php\/wp-json\/wp\/v2\/tags?post=4329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}