decoupling

How to decouple a class from it's attributes when the methods of the attributes need to modify state of the owning class?

给你一囗甜甜゛ 提交于 2021-01-29 15:38:01
问题 How do I decouple a class from its attributes when methods of the attributes need to modify the state of the owning class? Alternatively, how can I redesign the architecture so that this isn't a problem? This question is a bit abstract, but I keep coming across this problem time and time again. I spend a lot of time designing my code base so that my classes are "high cohesion and low coupling", but then as the code evolves over time, they end up becoming more closely coupled. I'll give the

How do you handle shared members when dealing with interfaces?

不问归期 提交于 2020-01-17 05:03:49
问题 So I did tons and tons of work trying to make an interface for a common set of classes. The idea was to make an interface that each class could use within the set, but ultimately each class is different. Turns out interfaces do not like shared members. What I tried: Public Interface ISomeInterface Shared Property Meta() as Object End Interface Public Class A Implements ISomeInterface Shared Public Property Meta() as Object Implements ISomeInterFace.Meta 'Set/get methods End Propery Public

Managing resources in a Python project

浪子不回头ぞ 提交于 2020-01-09 12:24:28
问题 I have a Python project in which I am using many non-code files. Currently these are all images, but I might use other kinds of files in the future. What would be a good scheme for storing and referencing these files? I considered just making a folder "resources" in the main directory, but there is a problem; Some images are used from within sub-packages of my project. Storing these images that way would lead to coupling, which is a disadvantage. Also, I need a way to access these files which

register a class in objective c

孤街浪徒 提交于 2020-01-07 02:33:08
问题 lets say i have classA which is a class of audio,that sample the audio input many times. each time class A get a new data (can happen many times in second), he needs to inform another class, which is classB . Now, i could just make an instance of class B in classA and call B when there is a new data arrived, but this is not a modular software. i want classA to be "blind" to the outside, and just to add him to every project, and to have another classB that will register him some how, so when A

PHP Pattern to Decouple UI Markup from Static Content

那年仲夏 提交于 2020-01-05 05:58:17
问题 I deal with a website that is composed of a lot of static content. One of the things that bothers me about the site is the amount of duplicate/one-off markup and that every time I have to change or update the UI, I have to modify a lot of different files and then make sure I didn't break anything. I was considering moving the website content to a PHP server and reorganizing the site contents to make my job easier. /* This is also something of an exercise for me. I wanted to get my feet wet

Passing a parameter through constructor

一曲冷凌霜 提交于 2019-12-25 04:19:16
问题 First I will present a quick outline of a somewhat tightly coupled classes (though not the worst possible case): class setUpGUI { ... JTextField output = new JTextField(); ... CountTimer ct; ... public void setOtputText(String text) { output.setText(text); public startTimer() { ct = new CountTimer(); } ... } class CountTimer implements ActionListener { private String text = ""; private gui = new SetUpGUI(); ... @Override public void actionPerformed(ActionEvent e) { ... gui.setOtputText(text);

Decoupling vs YAGNI

你。 提交于 2019-12-21 04:42:46
问题 Do they contradict? Decoupling is something great and quite hard to achieve. However in most of the applications we don't really need it, so I can design highly coupled applications and it almost will not change anything other than obvious side effects such as "you can not separate components", "unit testing is pain in the arse" etc. What do you think? Do you always try to decouple and deal with the overhead? 回答1: It seems to me decoupling and YAGNI are very much complementary virtues. (I

Best practice for Android MVVM startActivity

让人想犯罪 __ 提交于 2019-12-20 08:56:12
问题 I am building an Android App using MVVM and DataBinding. And I have a function inside my ViewModel that starts an Activity. Is it okay to have an onClick call inside a ViewModel? Like this. public class MyViewModel { public void onClick(View view, long productId) { Context context = view.getContext(); Intent intent = new Intent(context, ProductDetailActivity.class); intent.putExtra("productId", productId); context.startActivity(intent); } } And in my XML: ... android:onClick="@{(v) ->

Using deferred with jquery ajax calls and async processes along with user confirmation reading in between

浪尽此生 提交于 2019-12-13 03:20:45
问题 Background This is in continuation to my question Correct way to set up a sequence of synchronous/asynchronous functions all of which can stop form submission and further processing? I got the answer on what was the correct way (deferred pipe), but I am still not able to actually implement this. I just started reading on jquery deferred API today and I could not grasp much yet. The jQuery API documentations seem too complicated with little example. Could anyone put links to some basic demos

IoC and managing interfaces

醉酒当歌 提交于 2019-12-12 10:11:27
问题 Say I had a business object library which was using IoC to implement a data access library. Where should I define the Data Access Interface? Which library does it belong? Or should it be in a separate library just for interfaces? 回答1: I would define the interfaces within the business domain. Then the implementations of the interfaces would be in a library that references the business domain (and is referenced by whatever the application context is, or by an IoC library which is referenced by