design-patterns

Design pattern for managing queues and stacks?

浪尽此生 提交于 2020-02-21 06:18:29
问题 Is there a design pattern for managing a queue or a stack? For example, we are looking to manage a list of tasks. These tasks will be added to a group queue, users will then be able to pull off the queue and add them to their personal queue. 回答1: Design patterns can use queues and stacks, but the queues and stacks themselves don't really implement a design pattern, they implement an interface. Queues are typically FIFO while stacks are LIFO. Since many users might be using the data structures

Design pattern for managing queues and stacks?

穿精又带淫゛_ 提交于 2020-02-21 06:16:48
问题 Is there a design pattern for managing a queue or a stack? For example, we are looking to manage a list of tasks. These tasks will be added to a group queue, users will then be able to pull off the queue and add them to their personal queue. 回答1: Design patterns can use queues and stacks, but the queues and stacks themselves don't really implement a design pattern, they implement an interface. Queues are typically FIFO while stacks are LIFO. Since many users might be using the data structures

What's the point of separating the Model from the View Model? (MVVM)

﹥>﹥吖頭↗ 提交于 2020-02-15 08:20:24
问题 I don't think I understand the MVVM pattern properly because having a Model and ViewModel class seems redundant to me. My understanding of the Model is to basically add in minor details of a class and let the ViewModel handle all the logic and implementation. If that is the case why separate the two? Couldn't you create the variables, properties and such in the view model and still have the logic in there? To me it sounds like C++ in a way. You have the header file which describes the class

What's the point of separating the Model from the View Model? (MVVM)

为君一笑 提交于 2020-02-15 08:20:02
问题 I don't think I understand the MVVM pattern properly because having a Model and ViewModel class seems redundant to me. My understanding of the Model is to basically add in minor details of a class and let the ViewModel handle all the logic and implementation. If that is the case why separate the two? Couldn't you create the variables, properties and such in the view model and still have the logic in there? To me it sounds like C++ in a way. You have the header file which describes the class

Undo for a paint program

╄→尐↘猪︶ㄣ 提交于 2020-02-12 09:20:26
问题 I am looking into how to write a paint program that supports undo and seeing that, most likely, a command pattern is what I want. Something still escapes me, though, and I'm hoping someone can provide a simple answer or confirmation. Basically, if I am to embody the ability to undo a command, for instance stamping a solid circle on the screen, does this mean I need to essentially copy the frame buffer that the circle covers into memory, into this command object? I don't see any other way of

Undo for a paint program

佐手、 提交于 2020-02-12 09:20:23
问题 I am looking into how to write a paint program that supports undo and seeing that, most likely, a command pattern is what I want. Something still escapes me, though, and I'm hoping someone can provide a simple answer or confirmation. Basically, if I am to embody the ability to undo a command, for instance stamping a solid circle on the screen, does this mean I need to essentially copy the frame buffer that the circle covers into memory, into this command object? I don't see any other way of

What is the name of the design pattern used in method chaining in jQuery? [closed]

荒凉一梦 提交于 2020-02-07 06:10:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I want to know what is the name of the design pattern behind method chaining in jQuery? 回答1: According to this post https://softwareengineering.stackexchange.com/questions/137999/what-is-the-pattern-name-for-using-method-chaining-to-build-an-object, it's called a Fluent Interface

Is this a sane implementation of constructor injection?

北城以北 提交于 2020-02-05 08:18:59
问题 Following on from my question on service locators I have decided to use constructor injection instead. Please consider the following code: <?php interface IAppServiceRegistry { public function getDb(); public function getLogger(); } interface IFooServiceRegistry extends IAppServiceRegistry { public function getFooBarBazModel(); } class AppServiceRegistry implements IAppServiceRegistry, IFooServiceRegistry { private $logger; private $db; private $fooBarBazModel; public function getDb() { //

Qt “passthrough” or “container” widget

耗尽温柔 提交于 2020-02-05 02:36:32
问题 In Qt / PySide2, is there such a thing as a Qt widget that simply passes through to a wrapped widget, without adding any extra layers of layout etc. I'm coming from a web frontend background, so my mental model is of a React container component that adds some behavior but then simply renders a wrapped presentational component. However, there doesn't seem to be a way of doing this sort of thing in Qt without at least creating a layout in the wrapping widget, even if that layout only contains

Does Liskov Substitution Principle also apply to classes implementing an interface?

戏子无情 提交于 2020-02-03 11:00:22
问题 LSP states that classes should be substitutable for their base classes, meaning that derived and base classes should be semantically equivalent. But does LSP also apply to classes implementing an interface? In other words, if an interface method implemented by a class is semantically different from what user expects it to be, would this be considered as a violation of LSP? Thank you 回答1: No It only applies to subtypes. See the Wikipedia article for a brief summary. If you have a class B that