encapsulation

difference between encapsulation and abstraction concepts [duplicate]

独自空忆成欢 提交于 2019-12-06 01:18:18
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Abstraction VS Information Hiding VS Encapsulation Can somebody explain to me the main differences between the principles of encapsulation and abstraction in objected-oriented programming (if possible with examples). 回答1: Sample: // NO ABSTRACTION, NO ENCAPSULATION const int catLegs = 4; const int spiderLegs = 8; Leg[] catLegs; Leg[] spiderLegs; void MakeCatRun(Distance b) { for (int i=0; i<catLegs; ++i) catLegs

What is the difference between Public Property, Friend and Public Variable in VB6

不想你离开。 提交于 2019-12-05 18:19:21
问题 OK so I understand that ion VB6, encapsulated properties in a class can belong to one of three categories: Public Property Friend Public Variable What is the difference between these and how do these compare to public and private properties in a more modern language like C#? 回答1: The scope qualifiers Public and Friend determine whether clients in different projects can see the item. Public items will be accessible to client code in other projects 1 and code in the same project. Friend items

DDD and the use of Getters and Setters

为君一笑 提交于 2019-12-05 17:45:26
问题 I've read a few articles/posts regarding the use of Getters and Setters, and how they help to defeat the purpose of encapsulation in domain model objects. I understand the logic behind not using setters - you are allowing client code to manipulate attributes of that object, outside the context of the object business rules and invariants. Now this principal does still confuse me. For example, what happens if I need to change the value of a member variable of an object? For example, if the name

Celery dynamic tasks / hiding Celery implementation behind an interface

你说的曾经没有我的故事 提交于 2019-12-05 17:28:35
I am trying to figure out how to implement my asynchronous jobs with Celery, without tying them to the Celery implementation. If I have an interface that accepts objects to schedule, such as callables (Or an object that wraps a callable): ITaskManager(Interface): def schedule(task): #eventually run task And I might implement it with the treading module: ThreadingTaskManager(object) def schedule(task): Thread(task).start() # or similar But it seems this couldn't be done with celery, am I right? Perhaps one, albeit quite ugly, solution might be to define one celery task which dynamically loads

Extending a type in C++

♀尐吖头ヾ 提交于 2019-12-05 15:43:53
问题 Sadly, UFCS did not make it into C++17 and that left me with a recurring problem: Sometimes I want to give types extra functionality using the method call syntax (without writing global functions). That would especially come handy when dealing with monads. I see two options: One is inheritance, and the other is encapsulation. Because you cannot safely inherit from STL containers, that leaves encapsulation. For example, I want to extend std::optional , so I write: template <typename T> struct

Javascript static/singelton - this vs _this vs object name

家住魔仙堡 提交于 2019-12-05 12:08:26
This is a question about performance and best practice. Assuming I have a js object that encapsulates a large number of helper methods. The object is being treated as a static class, meaning it is never instantiated and all its methods are basically helper methods. When using events and jQuery, the object's this scope keeps changing, and since it has a fairly large number of methods I am wondering what is best practice - saving this into _this at the beginning of each method or simply use the object name MyObject . Over the years I've been doing both, when it comes to singelton/static objects,

Access Modifiers - what's the purpose?

旧巷老猫 提交于 2019-12-05 09:13:54
I'm relatively new to programming in general and I was wondering if anyone could help me understand the purpose of access modifiers? I understand the fact that they set different levels of access for classes and variables etc. but why would you want to limit what has access to these? What is the point in not allowing access for different things? why not just allow access for everything? Sorry if this is a stupid question! There are thousands of reasons, but I'll quote a few from here and then expand on those: Hiding the internals of the object protects its integrity by preventing users from

Should I encapsulate my IoC container?

耗尽温柔 提交于 2019-12-05 05:49:16
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. I'm trying to decide whether or not it makes sense to go through the extra effort to encapsulate my IoC container. Experience tells me that I should put a layer of encapsulation between my apps and any third-party component. I just don't know if this is bordering on overkill. I can think of situations where I might want to switch containers. For instance, my current container ceases to be maintained,

Encapsulation in the age of frameworks

青春壹個敷衍的年華 提交于 2019-12-05 05:36:19
At my old C++ job, we always took great care in encapsulating member variables, and only exposing them as properties when absolutely necessary. We'd have really specific constructors that made sure you fully constructed the object before using it. These days, with ORM frameworks, dependency-injection, serialization, etc., it seems like you're better off just relying on the default constructor and exposing everything about your class in properties, so that you can inject things, or build and populate objects more dynamically. In C#, it's been taken one step further with Object initializers,

How often do you see abuse of C# shorthand getters/setters?

做~自己de王妃 提交于 2019-12-05 05:31:15
In C# you can create getter/setters in a simpler way than other languages: public int FooBar { get; set; } This creates an internal private variable which you can't address directly, with the external property 'FooBar' to access it directly. My question is - how often do you see this abused? It seems like it has a high potential to violate encapsulation best-practices often. Don't get me wrong, I use it as appropriate, and partial variations of it for read-only write-only types of properties, but what are your unpleasant experiences with it from other authors in your code base? Clarification: