design-patterns

Log File Parser in Java

我的梦境 提交于 2020-01-16 08:47:29
问题 I am trying to design Log File Parser for my application. I have thousands of Log files having same pattern of data and my objective is to first parse the data and store it in a database. Log file has following pattern- a=some_value_1 b=some_value_2 c=some_value_3 d=some_value_4 a=some_value_5 b=some_value_6 c=some_value_7 d=some_value_8 a=some_value_9 b=some_value_10 c=some_value_11 d=some_value_12 a=some_value_13 b=some_value_14 c=some_value_15 d=some_value_16 My initial idea is to read all

Long inheritance hierarchy

a 夏天 提交于 2020-01-16 04:49:05
问题 I have very long class inheritance hierarchy. For example: -MyAbstractObject --MyAbstractUiObject ---MyAbstractTable -----MyAbstractPageableTable -------MyAbstractScrollableTable ---------MyAbstractStateblaTable etc... I read at Code complete that ideal inheritance deep is 3. And sometimes it allowable to make inheritance deep 7-9. But I have inheritance deep 11! How I can change my architecture? What design pattern is applicable to my case? And what is bad is that I can change places of

What are the use cases of having new() in “public T SomeMethod<T>(string item) where T : new();” [closed]

断了今生、忘了曾经 提交于 2020-01-16 01:01:10
问题 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 5 years ago . I am trying to identify various uses cases of using new() in statement public T SomeMethod<T>(string item) where T : new(); I know compiler will ensure that T must have a default constructor. But in what all scenario this is helpful. I have gone through this link 回答1: MSDN's own

Multiple language components/classes [OOP/Patterns/IoC/DI]

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-16 00:53:25
问题 I have several components for which there exists different versions, depending on the language used by the system (configurable, and can be changed at runtime). For example, I have an interface ("component") for Tokenizer , and two concrete implementations for english and chinese, like so: public interface Tokenizer { List<String> tokenize(String s); } public class EnglishTokenizer implements Tokenizer { List<String> tokenize(String s) { ... }; } public interface ChineseTokenizer implements

JavaScript Namespace Pattern

假如想象 提交于 2020-01-16 00:39:10
问题 I came across this JavaScript intricacy and was struggling to find the difference. Its about JavaScript namespaces. My question is simple, one form of namespace definition looks like this: var nameSpace = ( f )(); the other one looks like this var nameSpace = ( f ()); here f refers to the full function definition like function(vars) { ....}. I know that 1 executes the body before returning the handle to the return object. But how does 2 differ from 1 ? 回答1: They both accomplish the exact same

Pattern for concurrent cache sharing

ε祈祈猫儿з 提交于 2020-01-15 15:12:24
问题 Ok I was a little unsure on how best name this problem :) But assume this scenarion, you're going out and fetching some webpage (with various urls) and caching it locally. The cache part is pretty easy to solve even with multiple threads. However, imagine that one thread starts fetching an url, and a couple of milliseconds later another want to get the same url. Is there any good pattern for making the seconds thread's method wait on the first one to fetch the page , insert it into the cache

Is the dependency injection a cross-cutting concern?

风流意气都作罢 提交于 2020-01-15 11:48:11
问题 I am designing an app and I am using a n-layer architecture, I have: - a presentation layer - a domain bussines layer - a data acccess layer - a cross-cutting layer Then I am trying to isolate my project from an specific DI framework, that is create my own IContainer interface and ensure that my components depends only to this interface. Then I have 2 questions. 1 - Is this last a good practice ? 2 - (And the more important) Is dependency injection a cross-cutting concern ? That is can I

How can I create a plugin mechanism that calls functions only when the plugin is available?

不羁的心 提交于 2020-01-15 06:54:12
问题 Sorry if I am not clear enough, I've had a hard time writing this question. I downloaded an open source software. I would like to expand the functionalities so I would like to create modules that encapsulates the functionality these modules would be .dll files. I would like to have one completely independent from another: if I set a key to true in the config file and if the DLL is present on the folder, the plugin should be loaded. The problem is: how can I make the call for the plugin

How can i implement the NULL Object Design Pattern in a generic form?

岁酱吖の 提交于 2020-01-14 19:27:26
问题 Is there a way to implement the null object design pattern in a generic form so that i don't need to implement it for every buisness object. For me, there are two high level classes you'll need for every business class. One for a single record and another for a list. So i think there should be a way to implement the NULL Object design pattern at a high level and not have to implement it for every class. Is there a way and how please? 回答1: In my understanding, the NULL-class does not have to

What is the correct way of Message Passing between Classes in MVC?

倾然丶 夕夏残阳落幕 提交于 2020-01-14 14:57:27
问题 public void Model { private SwingPropertyChangeSupport spcs; public void updatedb(); public void addPropertyChangeListener(PropertyChangeListener listener) } public void Gui { private JFrame view; Gui() { view = new JFrame(); init();// for initilizing ui components EventQueue.invokeLater(new Runnable() { @Override public void run() { try { view.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } void addListener(ActionListener a); void init(); void updateGUI(); } public