design-patterns

How can I design this better? (Avoiding a switch statement with Object Oriented design)

試著忘記壹切 提交于 2020-01-29 03:05:27
问题 I know a little bit about Object Oriented design, but I'm not sure how to go about using those principles in my code. Here's what I'm working on: public void Query(Agency agency, Citation queryCitation) { queryCitation.AgencyCode = agency.AgencyCode; switch (agency.ClientDb.Type) { case "SQL": QueryOracle(agency, queryCitation); break; case "PIC": QueryPick(agency, queryCitation); break; } } (Most of these are objects from NHibernate. I'm working with a legacy database system and am

How to reuse existing connection in Open Session In view pattern implementation of Hibernate?

泄露秘密 提交于 2020-01-25 05:55:20
问题 I am using Hibernate by implementing "Open Session in view" pattern?It opens a new connection per request. Is there any way to use the existing connection? Is my understanding correct? May be i miss something during implementation which cause opening of new connection? 回答1: Advice: don't implement it yourself, use an existing one, like Spring's: Servlet 2.3 Filter that binds a Hibernate Session to the thread for the entire processing of the request. Intended for the "Open Session in View"

2 Threads vs 2 Processes (design/performance/isolation)

女生的网名这么多〃 提交于 2020-01-25 04:28:06
问题 I need to decide whether to use 2 threads, or 2 processes (in either case, both will connect to the same database). 2 threads would be able to share the same memory, and there's no need for them to write to that shared memory: even though they are doing different jobs, they will only read from the memory and not change it. So my questions are: Might I have a problem when 2 different programs insert or extract values from the database if they both run at the same time? (I know that I can

How to subscribe to an event without preventing garbage collection?

六眼飞鱼酱① 提交于 2020-01-24 18:40:49
问题 Let's say AppConfiguration.Instance is a singleton. Now let's say my UI dynamically adds a button that should change it's text if the configuration is change, so my app could do: AppConfiguration.Instance.Changed += Changed_Handler; On the button's code, but I don't wanna do that because that will prevent garbage collecion of the button after the user navigates to another screen and the button gets removed from the form My question is: Is there a design pattern for listening to an event

Design pattern for getting initial value in pubsub in autobahn

一曲冷凌霜 提交于 2020-01-24 18:25:15
问题 Normally, a publish-subscribe pattern is about fetching content updates. But how do subscribers get initial content that was there before they subscribed for updates? I'm using publish-subscribe examples within autobahn framework for my application. The publisher backend publishes a position of the robotic joint when the joint moves. The client frontend subscribes to the topic sometimes later. Due to the nature of the data, the initial value of the "topic" on the client is just as important

Design pattern for getting initial value in pubsub in autobahn

蹲街弑〆低调 提交于 2020-01-24 18:25:07
问题 Normally, a publish-subscribe pattern is about fetching content updates. But how do subscribers get initial content that was there before they subscribed for updates? I'm using publish-subscribe examples within autobahn framework for my application. The publisher backend publishes a position of the robotic joint when the joint moves. The client frontend subscribes to the topic sometimes later. Due to the nature of the data, the initial value of the "topic" on the client is just as important

How can I use observer design pattern?

拟墨画扇 提交于 2020-01-24 13:10:39
问题 I need to use the Observer design pattern for a school project, but I'm having problems with it. I have a timer and an int which decrements itself, I want to make an observer so when the int becomes 0, a jdialog pops up. Here is my code: public class Joc extends JPanel implements ActionListener { javax.swing.Timer t1; int time=0, MyObservator obs = new MyObservator(); public Joc() { ... // constructor stuff t1=new javax.swing.Timer(1000, (ActionListener) this); t1.start();} public void

Who's responsible for the next View?

限于喜欢 提交于 2020-01-24 09:25:07
问题 In an archetypical MVC architectur, where does the logic go, that determines which view to show next? The assumption is some kind of app with several views (windows) that may or may not be visible at different times, depending on user actions. For instance, sometimes the application may need the user to fill out a form with additional details, other times it may not. Is it the controllers responsibility to ask for a specifik view to become visible? Am I thinking about this wrong? Maybe the

Carry STRef implicitly in an environment during computation

这一生的挚爱 提交于 2020-01-24 09:20:06
问题 I am working on some bigger computation that requires use of mutable data in some critical moments. I want to avoid IO as much as I can. My model used to constist of ExceptT over ReaderT over State datatype, and now I want to replace State with mentioned ST . To simplify, let's assume I would like to keep single STRef with an Int during the whole computation, and let's skip the ExceptT outer layer. My initial idea was to put STRef s Int into ReaderT 's environment: {-#LANGUAGE Rank2Types#-} {

How can I repeatedly match from A until B in VIM?

我们两清 提交于 2020-01-24 01:39:16
问题 I need to get all text between <Annotation> and </Annotation> , where a word MATCH occurs. How can I do it in VIM? <Annotation about="MATCH UNTIL </Annotation> " timestamp="0x000463e92263dd4a" href=" 5raS5maS90ZWh0YXZha29rb2VsbWEvbGFza2FyaS8QyrqPk5L9mAI"> <Label name="las" /> <Label name="_cse_6sbbohxmd_c" /> <AdditionalData attribute="original_url" value="MATCH UNTIL </Annotation> " /> </Annotation> <Annotation about="NO MATCH" href="