问题标签 [interface-design]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
4 回答
2743 浏览

xhtml - Does anybody know of a mockup tool that can export into code?

I want a tool that allows me to design the screens pixel-by-pixel (almost like i took a screencap of the webpage) and gives me the option to export the entire screen into XHTML/CSS.
Does anybody know of such a tool?
As a note, I am NOT looking for something like Balsamiq. I want to create very detailed UIs--NOT wireframes.

0 投票
1 回答
82 浏览

java - 如果操作失败,则尝试强制转换返回 null 的命名模式的建议

我在很多地方都看到过这种模式,但从未见过它命名。

我更喜欢关于如何命名实现它的方法的建议,因为不同的人似乎使用不同的命名模式。

抱歉,我不记得任何库作为示例,但如果将其中一个用作您的答案的一部分,请命名它们。

额外的

@LouisWasserman

首先,通过将其 ctor 包设为私有来限制 Produce 的子类型的数量。通过包含 2 个 isXXX 方法,我说明了一个事实,即只有 2 个子类,这比进行 instanceof 检查要好。也许只有我,但是,这种方法也意味着在其他代码或上述代码中没有强制转换,这一定是件好事,对吧?

当搜索或查询失败时,也不会从方法返回一个空列表,这与在尝试将 Veg 转换为 Fruit 时返回 null 以标记操作 isFruit() 失败类似吗?

我在 JType 中的 GWT 中找到了一个快速示例,我相信它是 Eclipse JDT 的克隆。无论如何,起源并不重要,但在这里我们有两种非常知名的产品,完全符合我的描述......

http://code.google.com/p/google-web-toolkit/source/browse/trunk/dev/core/src/com/google/gwt/core/ext/typeinfo/JType.java

还有很多其他 isXXX 尝试强制转换或返回 null,我在下面粘贴了一些。

0 投票
2 回答
1738 浏览

html - 如何在行之间的分隔符上添加一些文本?

示例(以“OR”作为文本):

示例(与

submit这个想法是,在列折叠时 - 即:在移动大小的屏幕上查看 - 它会出现在Click me.

如何在行之间的分隔符上添加一些文本?

0 投票
5 回答
289 浏览

c# - 如何表达一个参数需要在 C# 中实现多个接口

类似于这个问题:我如何需要一个方法参数来实现多个接口? 我想要一个方法参数来实现几个接口。

接口应该可以以任意方式组合,我不想为每个有效组合创建一个接口。

想一个文件。有可能:

  1. 可读 =>IReadable
  2. 可写 =>IWriteable
  3. 档案=>IArchive
  4. 自动生成 =>IGenerated

...

如果我想表达一个参数需要是一个可写的、生成的存档,我不想生成IWritableGeneratedArchive,因为组合太多,我想将它与一些我无法修改的现有类一起使用。

伪代码:

0 投票
1 回答
581 浏览

c++ - 如何在 C 和 C++ 中设计具有并行接口的库

我当前的项目是一个中型库,旨在同时具有 C 和 C++ 接口。它以我希望从 C 和 C++ 函数访问的单一数据类型为中心,因为我想鼓励第三方通过用任何一种语言编写函数来扩展库。

我了解 C/C++ 混合的基础知识(例如比较http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html)并提出了以下解决方案:

我的基本设计围绕在 C 中创建一个所有数据都暴露的结构(这是我的 C 程序员所期望的)并从中派生一个隐藏成员访问的类,希望为 C++ 程序员更安全地访问该结构。问题来自推导:我想在 C++ 中使用命名空间并隐藏 C 接口。当然,C 结构本身不能隐藏(不使用 PIMPL 习语),但这对我来说很好。

以下示例代码在 C 和 C++“客户端”程序中编译和运行时没有明显错误。但是,我想知道这个解决方案是否有效或者是否有更好的解决方案。

示例代码:

0 投票
4 回答
106 浏览

c# - 为什么要尽可能争取多个界面成员?

一般来说,为什么要为每个界面争取三到五个成员?

然后,这样的事情有什么问题?

当我看到这个时,它会尖叫“反模式!” 因为接口没有完成任何事情,特别是当应用程序的设计者打算让每个接口与实现它的类具有一对一的关系时。

阅读:一旦一个接口被实现,它就再也不会被重新实现。现在,我没有设计这个系统,在我看来他们想要做的是实现某个版本的命令模式,但是在与开发人员交谈时,他们似乎没有得到它。

0 投票
3 回答
835 浏览

c++ - 使用传递引用而不是传递指针时的二进制兼容性

这个问题旨在作为这个问题的后续问题:C++ 中的指针变量和引用变量有什么区别?

阅读了我在 stackoverflow 上找到的答案和一些进一步的讨论后,我知道编译器应该像对待传递指针一样对待传递引用,并且引用只不过是语法糖。考虑到二进制兼容性,我还无法弄清楚一件事是否有任何区别。

在我们的(多平台)框架中,我们要求在发布和调试版本之间(以及框架的不同版本之间)二进制兼容。特别是,我们在调试模式下构建的二进制文件必须可用于发布版本,反之亦然。为此,我们只在接口中使用纯抽象类和 POD。

考虑以下代码:

ISerializer也是IException纯抽象类。ISerializer必须指向一个现有的对象,所以我们总是必须执行一个 NULL 指针检查。IException实现某种异常处理,其中指针指向的地址必须更改。出于这个原因,我们使用指向指针的指针,它也必须进行 NULL 指针检查。

为了使代码更加清晰并摆脱一些不必要的运行时检查,我们希望使用 pass-by-reference 重写此代码。

这似乎没有任何缺陷。但是这是否仍然满足二进制兼容性的要求仍然是我们的问题。

更新: 澄清一下:这个问题与代码的指针传递版本和引用传递版本之间的二进制兼容性无关。我知道这不能是二进制兼容的。事实上,我们有机会重新设计我们的 API,我们考虑使用传递引用而不是传递指针而不关心二进制兼容性(新的主要版本)。当仅使用代码的传递引用版本时,问题只是关于二进制兼容性。

0 投票
2 回答
1125 浏览

web-services - RESTful API 最佳实践

我是一名 Android 开发人员,并且对 RESTful API 开发也有一些了解。目前我正在使用 Dot Net Web API 构建一个 API。一切正常,但我仍然关心设计。

我现在最关心的是响应的元数据到底应该是什么,就像除了“响应代码”和“响应消息”之外我可以添加的其他有用元素。

我关心的第二个问题是请求是异步的还是查询,或者两者兼而有之。

最后一个问题是我应该使用什么技术来进行有状态的通信,如 JWT 或基本身份验证等。无状态。

0 投票
1 回答
104 浏览

java - 访问返回到其 API 的对象上的实现特定方法

让我从抽象地表述问题开始:我有两种公共接口类型。其中一个包含一个方法,该方法至少接收另一个接口类型的两个实例。方法的实现取决于传递的对象的实现。

考虑以下公共 API,它由两个接口组成:

现在,我想实现该 API,如下所示:

我需要访问connect方法中的包装对象,这是不可能的,因为该getWrapped方法不是 API 的一部分。这是一个实现细节。

所以问题是:如何在connect不向 API 泄​​露实现细节的情况下实现该方法?

这是我到目前为止所尝试的:

  • connect方法放入Node接口并调用parent.connect(child). 这使我可以访问父对象的包装对象,但是子对象的包装对象仍然不可用。

  • 只需假设传递Node的是类型NodeImpl并使用向下转换。这对我来说似乎是错误的。可能还有其他Node实现。

  • 不要将包装的对象放在节点中,而是使用映射到对象的TreeImpl映射。NodeWrapped这与上面的基本相同。一旦将Node实例传递给connect没有关联映射的方法,它就会崩溃。

请注意,Node接口可能包含方法。但是,这对于这个问题并不重要。

另外,请注意我同时控制:接口声明和实现。


解决这个问题的另一个尝试是将connect方法转换为接口addChild中的方法Node并使Node接口通用:

Node并且createNode是公共 API 的一部分。NodeImpl并且Wrapped应该被隐藏。run是客户端代码。如您所见,NodeImpl必须对客户端可见,因此这仍然是一个泄漏的抽象。

0 投票
3 回答
2259 浏览

class-design - How do I set properties in a constructor that has only a self argument. I also do not know how to define methods without implementation,Inside a class

This is the Question: It blew me away; my attempt is in my next post.

Create a class called bank account that has the methods withdraw and deposit with no implementation.

Create a class called savings account that inherits from bank account. SavingsAccount should have a constructor that only takes in a self argument. This constructor sets a property called balance to 500. (This should be the minimum balance at any given time).

In the savings account class, implement the deposit method that takes in cash deposit amounts, updates the balance accordingly and then returns the balance. For a negative deposit amounts, return invalid deposit amount. In the savings account class, implement the withdraw method that takes in the cash withdrawal amount, deducts this amount from the current balance and returns the balance. This method should never allow the balance to get below 500. (Check for this condition and output Cannot withdraw beyond the minimum account balance if it happens). Also, output Cannot withdraw beyond the current account balance if withdrawal amount is greater than current balance. For a negative withdrawal amount, return Invalid withdraw amount.

Create a class called current account that inherits from bank account. CurrentAccount should have a constructor that only takes in the self argument and sets a property called balance to 0.

In the current account class, implement a deposit method that takes in cash deposit amounts, updates the balance accordingly and then returns the balance. For a negative deposit amount, return invalid deposit amount. In the current account class, implement a withdraw method that takes in the cash withdrawal amount, deducts this amount from the current balance and returns the balance. For a negative withdrawal amount, return invalid withdraw amount. Withdrawing more than the current balance should fail with message cannot withdraw beyond the current account balance.

Here is my attempt: