Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
作为我们应用程序的一部分,我需要构建将在 php 和 asp 中输出具有相同功能的代码(可能是后者的 jsp)的组件。我怎样才能将这种组件设计为尽可能通用?
我个人会选择Strategy Pattern。您可以拥有一个主代码生成器类并使用策略对其进行实例化。
PHPCodeStrategy ASPCodeStrategy
然后每个人都会有一个名为 execute 的方法。然后,您可以添加更多策略并扩展您的应用程序。
安德鲁
您需要能够从所有输入语言中创建解析树。
对于每种输出语言,您都需要创建一组树转换语法。
您可能还需要一个运行时库来帮助翻译在您的输出语言中不可用的例程。