design-patterns

Whats the best practice for creating Stateless Utility classes in Java [closed]

痴心易碎 提交于 2020-12-28 14:58:01
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . Improve this question What's the best practice for creating the Utility (which do not hold any state) classes in Java. In most of the cases we end up creating static methods for such tasks. Other possible way could be "create the singleton objects" for performing this

How to design a loader for different types of images?

丶灬走出姿态 提交于 2020-12-12 17:10:19
问题 I'm working on a side project that does matrix calculations over a large number of images. To achieve this, I'm using several different libraries (including libpng, libjpg, libtiff and easybmp) to load, maybe preprocess (i.e. grayscale or resize), and store the images. Each of these libraries stores the images differently, and this is where the issue occurs. I want to use strategy to have a base class named Image and multiple derived classes (i.e. ImagePNG, ImageBMP, etc.), and factory to

How to design a loader for different types of images?

偶尔善良 提交于 2020-12-12 17:09:34
问题 I'm working on a side project that does matrix calculations over a large number of images. To achieve this, I'm using several different libraries (including libpng, libjpg, libtiff and easybmp) to load, maybe preprocess (i.e. grayscale or resize), and store the images. Each of these libraries stores the images differently, and this is where the issue occurs. I want to use strategy to have a base class named Image and multiple derived classes (i.e. ImagePNG, ImageBMP, etc.), and factory to

How to design a loader for different types of images?

◇◆丶佛笑我妖孽 提交于 2020-12-12 17:09:32
问题 I'm working on a side project that does matrix calculations over a large number of images. To achieve this, I'm using several different libraries (including libpng, libjpg, libtiff and easybmp) to load, maybe preprocess (i.e. grayscale or resize), and store the images. Each of these libraries stores the images differently, and this is where the issue occurs. I want to use strategy to have a base class named Image and multiple derived classes (i.e. ImagePNG, ImageBMP, etc.), and factory to

Can I say that the relation between events and delegates adopts composite pattern?

邮差的信 提交于 2020-12-08 16:18:21
问题 An event can contain many handlers which are defined using delegate , my current understanding is that delegate is just an abstraction of function pointer. Since an event , which associated with a delegate type, can add / remove many delegates into it, and composite pattern treats a composite object the same as the terminal object, so the idea is: composite.onTriggered(); // Internally: // foreach(handler in composite) // { // handler.onTriggered(); // } will in turn call every handlers

Can I say that the relation between events and delegates adopts composite pattern?

二次信任 提交于 2020-12-08 16:13:23
问题 An event can contain many handlers which are defined using delegate , my current understanding is that delegate is just an abstraction of function pointer. Since an event , which associated with a delegate type, can add / remove many delegates into it, and composite pattern treats a composite object the same as the terminal object, so the idea is: composite.onTriggered(); // Internally: // foreach(handler in composite) // { // handler.onTriggered(); // } will in turn call every handlers

Can I say that the relation between events and delegates adopts composite pattern?

只谈情不闲聊 提交于 2020-12-08 16:08:45
问题 An event can contain many handlers which are defined using delegate , my current understanding is that delegate is just an abstraction of function pointer. Since an event , which associated with a delegate type, can add / remove many delegates into it, and composite pattern treats a composite object the same as the terminal object, so the idea is: composite.onTriggered(); // Internally: // foreach(handler in composite) // { // handler.onTriggered(); // } will in turn call every handlers

Can somebody recommend a java 8 pattern to replace a switch statement?

我是研究僧i 提交于 2020-12-02 07:23:38
问题 I have following code: public class A { private String type; String getType() { return type;} } Now in many code places I have code like this switch (a.geType()) { case "A" : return new Bla(); case "B" : return new Cop(); } or somewhere else switch (a.geType()) { case "A" : return new Coda(); case "B" : return new Man(); } (Note that I know I should use an Enumeration in production code). What I want to achive is that when a new type is added to class A the compiler should flag all the switch

Replace switch statement

给你一囗甜甜゛ 提交于 2020-11-30 02:09:27
问题 I have to calculate the price based on multiple input variables public class Model { public int Account { get; set; } public long Related{ get; set; } public int TransactionType { get; set; } public string detail{ get; set; } public int PlanId { get; set; } } First switch starts with TransactionType . Based on TransactionType I need to use Account,PlanId ,Related fields for more information from database to get more information and some configurable information. There are more conditions

Replace switch statement

99封情书 提交于 2020-11-30 02:07:16
问题 I have to calculate the price based on multiple input variables public class Model { public int Account { get; set; } public long Related{ get; set; } public int TransactionType { get; set; } public string detail{ get; set; } public int PlanId { get; set; } } First switch starts with TransactionType . Based on TransactionType I need to use Account,PlanId ,Related fields for more information from database to get more information and some configurable information. There are more conditions