software-design

Java: Iterator is supposed to always return the same object, but should change it between calls of next()

邮差的信 提交于 2021-01-29 09:36:49
问题 The Iterator I'm writing is supposed to iterate through all fixed-sized connected subgraphs of another given graph. As these subgraphs are all very similar (only minor changes in a search-tree based algorithm), I don't want to create a new object to return on each call of next() because of runtime concerns. Therefore I have an object subGraph that is returned every time, but is changed by a function update() between calls of next() , so that the object works like a view of the current state

How shoul I test logic that contains calls to aquire current date?

家住魔仙堡 提交于 2021-01-29 08:52:12
问题 For example, I have this Kotlin class and method (Spring-managed class if it matters): import org.springframework.stereotype.Service import java.time.LocalDateTime data class TestObj( val msg: String, val dateTime: LocalDateTime ) @Service class TestAnotherService { fun doSmthng1(testObj: TestObj) { println("Oh my brand new object : $testObj") } } @Service class TestService( private val testAnotherService: TestAnotherService ) { fun doSmthng() { testAnotherService.doSmthng1(TestObj("my

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

不羁岁月 提交于 2021-01-08 02:04:15
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

回眸只為那壹抹淺笑 提交于 2021-01-08 02:01:27
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

ε祈祈猫儿з 提交于 2021-01-08 02:01:24
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

懵懂的女人 提交于 2021-01-08 02:01:15
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

How to avoid writing confusing DSLs in Scala

穿精又带淫゛_ 提交于 2020-08-07 05:23:07
问题 I've read comments stating that Scala's flexibility makes it easy for developers to write DSLs that are difficult to understand and reason about. DSLs are possible because we can sometimes omit . and parentheses (e.g. List(1) map println ) we can sometimes interchange () and {} we have implicit values, parameters, and classes (also conversions, which are now discouraged) there is a relatively small number of reserved symbols in the language (e.g. I can define + for my class) and possibly

How to avoid writing confusing DSLs in Scala

萝らか妹 提交于 2020-08-07 05:22:19
问题 I've read comments stating that Scala's flexibility makes it easy for developers to write DSLs that are difficult to understand and reason about. DSLs are possible because we can sometimes omit . and parentheses (e.g. List(1) map println ) we can sometimes interchange () and {} we have implicit values, parameters, and classes (also conversions, which are now discouraged) there is a relatively small number of reserved symbols in the language (e.g. I can define + for my class) and possibly

Why use classes in php?

老子叫甜甜 提交于 2020-07-15 15:11:10
问题 I want to know why we use classes in php. I have seen in all of open source they use classes for executing query. It means they use classes for getting results, insert query etc. I think this is used for consistency and speedup, but as my knowledge if we execute query using mysql_query() , rather than creating an object link $db->query will execute fast as compare to second one because in object it will goto the function and then it execute it there and after that it return the result but in