software-design

adapter-Any real example of Adapter Pattern

被刻印的时光 ゝ 提交于 2019-11-27 10:14:31
I want to demonstrate use of Adapter Pattern to my team. I've read many books and articles online. Everyone is citing an example which are useful to understand the concept (Shape, Memory Card, Electronic Adapter etc.), but there is no real case study. Can you please share any case study of Adapter Pattern? p.s. I tried searching existing questions on stackoverflow, but did not find the answer so posting it as a new question. If you know there's already an answer for this, then please redirect. Fuhrmanator Many examples of Adapter are trivial or unrealistic ( Rectangle vs. LegacyRectangle,

Why encapsulation is an important feature of OOP languages? [closed]

喜你入骨 提交于 2019-11-27 07:27:34
I came across different interview where question was asked to me why encapsulation is used? Whose requirement actually is encapsulation? Is it for users of program? Or is it for co-workers? Or is it to protect code from hackers? BartoszKP Encapsulation helps in isolating implementation details from the behavior exposed to clients of a class (other classes/functions that are using this class), and gives you more control over coupling in your code. Consider this example, similar to the one in Robert Martin's book Clean Code : public class Car { //... public float GetFuelPercentage() { /* ... */

Utility classes are evil? [closed]

心不动则不痛 提交于 2019-11-27 06:09:48
I saw this thread If a "Utilities" class is evil, where do I put my generic code? and thought why are utility classes evil? Lets say I have a domain model that is dozens of classes deep. I need to be able to xml-ify instances. Do I make a toXml method on the parent? Do I make a MyDomainXmlUtility.toXml helper class? This is a case where the business need spans the entire domain model -- does it really belong as an instance method? What about if there are a bunch of auxiliary methods on the xml functionality of the application? Thomas Owens Utility classes aren't exactly evil, but they can

Clean Architecture - Robert Martin - How to connect use cases

倖福魔咒の 提交于 2019-11-27 00:57:59
问题 I'm trying to implement the Clean Architecture described by Robert Martin. More specifically I'm using VIPER which is an iOS version of Clean Architecture. The problem I have is as follows: The user starts looking at a map with places (pins) on it. If he clicks a button, a pin is dropped and he is taken to another view to create (or edit if it was a click to an existent pin) the place (or cancel). In this other view, the user can edit the place's information and then click "back" or "done"

What is the benefit of using Fragments in Android, rather than Views?

旧城冷巷雨未停 提交于 2019-11-26 23:28:35
When developing for Android , you can set your target (or minimum) sdk to 4 (API 1.6) and add the android compatibility package (v4) to add support for Fragments . Yesterday I did this and successfully implemented Fragments to visualize data from a custom class. My question is this: what is the benefit for using Fragments as opposed to simply getting a View from a custom object, and still supporting API 1.5? For example, say I have the class Foo.java: public class Foo extends Fragment { /** Title of the Foo object*/ private String title; /** A description of Foo */ private String message; /**

How do I choose heap allocation vs. stack allocation in C++?

蓝咒 提交于 2019-11-26 23:03:32
问题 One of the C++ features that sets it apart from other languages is the ability to allocate complex objects as member variables or local variables instead of always having to allocate them with new . But this then leads to the question of which to choose in any given situation. Is there some good set of criteria for choosing how to allocate variables? When should I declare a member variable as a straight variable instead of as a reference or a pointer? When should I allocate a variable with

Is it the best practice to extract an interface for every class?

╄→гoц情女王★ 提交于 2019-11-26 22:39:32
问题 I have seen code where every class has an interface that it implements. Sometimes there is no common interface for them all. They are just there and they are used instead of concrete objects. They do not offer a generic interface for two classes and are specific to the domain of the problem that the class solves. Is there any reason to do that? 回答1: After revisiting this answer, I've decided to amend it slightly. No, it's not best practice to extract interfaces for every class. This can

What is a software framework? [closed]

六月ゝ 毕业季﹏ 提交于 2019-11-26 21:08:49
Can someone please explain me what a software framework is? Why do we need a framework? What does a framework do to make programming easier? Neha Choudhary I'm very late to answer it. But, I would like to share one example, which I only thought of today. If I told you to cut a piece of paper with dimensions 5m by 5m, then surely you would do that. But suppose I ask you to cut 1000 pieces of paper of the same dimensions. In this case, you won't do the measuring 1000 times; obviously, you would make a frame of 5m by 5m, and then with the help of it you would be able to cut 1000 pieces of paper

Encapsulation vs Data Hiding - Java

一个人想着一个人 提交于 2019-11-26 18:58:15
问题 Interviewer: What is encapsulation and how do you achieve it in Java? Me: Encapsulation is a mechanism to hide information from the client. The information may be data or implementation or algorithm. We achieve this using access modifiers. Interviewer: This is data hiding. How do we achieve encapsulation in Java? Me : uummmm Concrete Question: Other than 'Access Modifiers', what is the way to implement Encapsulation in Java? 回答1: More generally encapsulation refers simply to bundling the data

Avoiding Circular Dependencies of header files [duplicate]

荒凉一梦 提交于 2019-11-26 17:22:44
This question already has an answer here: Resolve build errors due to circular dependency amongst classes 11 answers Do you have any good advice on how to avoid circular dependencies of header files , please? Of course, from the beginning, I try to design the project as transparent as possible. However, as more and more features and classes are added, and the project gets less transparent, circular dependencies start happening. Are there any general, verified, and working rules? Thanks. If you have circular dependency then you doing something wrong. As for example: foo.h ----- class foo {