encapsulation

Difference between Encapsulation and Abstraction

我的未来我决定 提交于 2019-12-17 17:24:30
问题 I had an interview today. I had a question from OOP , about the difference between Encapsulation & Abstraction ? I replied her to my knowledge that Encapsulation is basically to bind data members & member functions into a single unit called Class . Whereas Abstraction is basically to hide complexity of implementation & provide ease of access to the users. I thought she would be fine with my answer. But she queried, if the purpose of both are to hide information then what is the actual

Why doesn't PHP permit private const?

吃可爱长大的小学妹 提交于 2019-12-17 15:53:13
问题 I have a class that benefits from the use of constants in its internal implementation, but I would like to limit visibility of these constants. Why doesn't PHP permit private constants? Is there another way to achieve this or is PHP trying to discourage some type of design misstep I am ignorant of? 回答1: Use private static properties. In that case you will have the same variable throughout all objects and if you want to extend its scope to nested, you can expose a getter method to get its

Do objects encapsulate data so that not even other instances of the same class can access the data?

随声附和 提交于 2019-12-17 14:05:11
问题 In Java, Do objects encapsulate data so that not even other instances of the same class can access the data? Only when the keyword "private" is used? What are "accessor methods" in Java - methods like getName()? Thanks 回答1: I don't tend to think of it in terms of one object having access to another, but rather what code has access to what data within an object. In Java (and C#, btw) code within a class has access to the private members of any object of the same class. Then you've got package

Do objects encapsulate data so that not even other instances of the same class can access the data?

我们两清 提交于 2019-12-17 14:04:51
问题 In Java, Do objects encapsulate data so that not even other instances of the same class can access the data? Only when the keyword "private" is used? What are "accessor methods" in Java - methods like getName()? Thanks 回答1: I don't tend to think of it in terms of one object having access to another, but rather what code has access to what data within an object. In Java (and C#, btw) code within a class has access to the private members of any object of the same class. Then you've got package

Check if class is derived from a specific class (compile, runtime both answers available)

对着背影说爱祢 提交于 2019-12-17 11:55:27
问题 It is easier to explain on an example so, class base { //.... } class derived1 : public base { //... } In my library, there is a pointer of base class. The user of the library have to make classes derived from either base or derived1 and assign pointer to that class. How can I check what class is user-defined class derived from? 回答1: I have some remarks on the proposed compile-time x runtime solutions. In addition to when they are evaluated, is_base_of and dynamic_cast have different

SQL Server: How to permission schemas?

ぐ巨炮叔叔 提交于 2019-12-17 09:22:22
问题 Inspired by various schema related questions I've seen... Ownership chaining allows me to GRANT EXECUTE on a stored procedure without explicit permissions on tables I use, if both stored procedure and tables are in the same schema. If we use separate schemas then I'd have to explicitly GRANT XXX on the the different-schema tables. The ownership chaining example demonstrates that. This means the stored proc executing user can read/write your tables directly. This would be like having direct

SQL Server: How to permission schemas?

浪尽此生 提交于 2019-12-17 09:21:09
问题 Inspired by various schema related questions I've seen... Ownership chaining allows me to GRANT EXECUTE on a stored procedure without explicit permissions on tables I use, if both stored procedure and tables are in the same schema. If we use separate schemas then I'd have to explicitly GRANT XXX on the the different-schema tables. The ownership chaining example demonstrates that. This means the stored proc executing user can read/write your tables directly. This would be like having direct

Java Encapsulation Concept not clear

五迷三道 提交于 2019-12-17 07:19:45
问题 This is basic question but still i don't understand encapsulation concept . I did't understand how can we change the properties of class from other class.because whenever we try to set the public instance value of class we have to create object of that class and then set the value.and every object refer to different memory.so even if we change the instance value this will not impact to any other object. Even I try to change using static public instance value also i am not able to change the

Java Encapsulation Concept not clear

寵の児 提交于 2019-12-17 07:19:02
问题 This is basic question but still i don't understand encapsulation concept . I did't understand how can we change the properties of class from other class.because whenever we try to set the public instance value of class we have to create object of that class and then set the value.and every object refer to different memory.so even if we change the instance value this will not impact to any other object. Even I try to change using static public instance value also i am not able to change the

accessing a protected member of a base class in another subclass

蓝咒 提交于 2019-12-17 06:38:05
问题 Why does this compile: class FooBase { protected: void fooBase(void); }; class Foo : public FooBase { public: void foo(Foo& fooBar) { fooBar.fooBase(); } }; but this does not? class FooBase { protected: void fooBase(void); }; class Foo : public FooBase { public: void foo(FooBase& fooBar) { fooBar.fooBase(); } }; On the one hand C++ grants access to private/protected members for all instances of that class, but on the other hand it does not grant access to protected members of a base class for