design-patterns

What's the difference between the Service Locator and the Factory Design pattern?

岁酱吖の 提交于 2020-05-25 04:09:33
问题 I'm using unity and I'm creating a class that wrapps it and I dont' know how to call it, service locator or factory, both encapsulate the creation of the objects, so.... what's the difference? 回答1: A factory creates objects for you, when requested. Service locator returns objects that may already exist, that is services that may already exist somewhere for you. Just think about the meaning of the names: Factory: is a place where objects are created. Service: is something that can do something

Creating view-model for each UITableViewCell

帅比萌擦擦* 提交于 2020-05-24 08:05:07
问题 I'm stuck on a design decision with creating view-models for table view's cells. Data for each cell is provided by a data source class (has an array of Contacts ). In MVVM only view-model can talk to model, but it doesn't make sense to put data source in view-model because it would make possible to access data for all cells, also it's wrong to put data source in view controller as it must not have reference to the data. There are some other key moments: Each cell must have it's own instance

What's the correct way to have Singleton class in c# [duplicate]

浪子不回头ぞ 提交于 2020-05-24 07:56:29
问题 This question already has answers here : Singleton Pattern for C# [closed] (8 answers) Closed 2 years ago . I am learning Singleton design pattern in C#, and I have written below code in two ways, and I want to know Which one is the right way to create a Singleton class: public sealed class TranslationHelper { // first way private static readonly TranslationHelper translationHelper = new TranslationHelper(); // second way public static readonly TranslationHelper translationHelpers = new

WPF. Pattern animation class

家住魔仙堡 提交于 2020-05-17 08:50:48
问题 [I created a DrawingLine animation class to draw patterns. The constructor starts the process of creating and animating lines: internal DrawingLine(double x, double y, int _thickness, Brush _brush, Canvas _canvas) At the end of the animation, this method generates a new line: void CreateNewLine(object sender, EventArgs e) { Line newLine = new Line(); switch (lines.Count % 2 == 0) { case true: { if (lines.Count < 18) { newLine.X1 = 0; newLine.Y1 = 180 - offset; newLine.X2 = 0; newLine.Y2 = 180

WPF. Pattern animation class

帅比萌擦擦* 提交于 2020-05-17 08:50:06
问题 [I created a DrawingLine animation class to draw patterns. The constructor starts the process of creating and animating lines: internal DrawingLine(double x, double y, int _thickness, Brush _brush, Canvas _canvas) At the end of the animation, this method generates a new line: void CreateNewLine(object sender, EventArgs e) { Line newLine = new Line(); switch (lines.Count % 2 == 0) { case true: { if (lines.Count < 18) { newLine.X1 = 0; newLine.Y1 = 180 - offset; newLine.X2 = 0; newLine.Y2 = 180

Design pattern - Is this a good way to use the command pattern?

喜夏-厌秋 提交于 2020-05-15 08:01:09
问题 I have a java class SearchFilterWebPage which represents a web page for an online shopping website. All of its (filter) methods allow you to set a filter, just like you would on a real shopping website. For example enterPriceRange(min, max), selectBrandsFilter(String...brands), and selectFreeShippingOnlyFilter() . The below code is very simple and only prints messages. I made a function applyMultipleFilters(FilterCommand [] functions) which allows you to call any number of filter functions of

How to avoid downcasting in this specific class hierarchy design?

让人想犯罪 __ 提交于 2020-05-13 14:09:57
问题 I've got an assignment to create a sort of a multi-platform C++ GUI library. It wraps different GUI frameworks on different platforms. The library itself provides an interface via which the user communicates uniformly regardless of the platform he's using. I need to design this interface and underlying communication with the framework properly. What I've tried is: Pimpl idiom - this solution was chosen at first because of its advantages - binary compatibility, cutting the dependency tree to

BASH - file selection by multiple patterns in zenity

蓝咒 提交于 2020-05-13 05:48:08
问题 Im pretty new to zenity and bash. Im trying to make file selection window that will display only the ones with .ogg, .aac and .wav extension. I tried this, but it doesn't work. option=`zenity --file-selection --file-filter=*.ogg | *.aac` For one extension it's working as intented: option=`zenity --file-selection --file-filter=*.ogg` Zenity man provides information: --file-filter=NAME | PATTERN1 PATTERN2 Sets a filename filter I dont really understand how am I supposed to use it. Can someone

Why singleton breaks open/closed principle?

北城余情 提交于 2020-05-13 03:38:41
问题 Could anyone tell me why does singleton break open/closed principle? Is it because there could be problems with inheriting from that class? 回答1: For a class to be "open" it must be possible to inherit from it. Inheritance is an "is-a" relationship. If you inherit from a singleton-class then instances of the child-class are also instances of the parent class due to the "is-a" relationship, meaning you can suddenly have multiple instances of the singleton class. If the singleton class inhibits

Why singleton breaks open/closed principle?

时光毁灭记忆、已成空白 提交于 2020-05-13 03:37:32
问题 Could anyone tell me why does singleton break open/closed principle? Is it because there could be problems with inheriting from that class? 回答1: For a class to be "open" it must be possible to inherit from it. Inheritance is an "is-a" relationship. If you inherit from a singleton-class then instances of the child-class are also instances of the parent class due to the "is-a" relationship, meaning you can suddenly have multiple instances of the singleton class. If the singleton class inhibits