encapsulation

When to create helper methods and separate files

£可爱£侵袭症+ 提交于 2019-12-24 08:22:42
问题 Background: I have a large (several hundred lines) class that manages a concept based on some primitive-type data structures long[] slist; //list of unique patterns (related to polyominoes) int[][][] sref;//patterns at each place [location][depth][<list of indices in slist>] Question: The two methods that populate and update these data are going to be quite long, with handfuls of 5-20 line tasks, some shared, others unique. I probably want to make a helper method for each sub-task. update(...

Is encapsulation possible without OOP?

放肆的年华 提交于 2019-12-24 08:09:15
问题 I was asked a question in an interview: if encapsulation is possible without OOP, e.g. in a procedural language? 回答1: Bob Martin has stated that encapsulation is not only possible without OOP, it was better before OOP came along. Here is an excerpt from a talk he gave in 2014 at Yale School of Management. We had perfect encapsulation. In C, all you had to do was forward declare your functions and your data structures. You didn't have to implement them. You would forward declare them in a

Angular2 css file with class conflict

喜欢而已 提交于 2019-12-24 07:12:47
问题 I use 2 css file but in these two file, i have a class with the same name... I use one in a component and the second in an another component. How use these CSS file to have no more conflict ? Thx in advance ! 回答1: I would say: Change class name. Instead of have 2 classes called myClass , make myClassUsers and myClassClients , for example. Change the way you reference them to be more precise, making use of other classes that are actually unique to each component. Example: CSS file 1: div

Private class members not fully encapsulated?

て烟熏妆下的殇ゞ 提交于 2019-12-24 05:57:59
问题 This is a follow up post from Instance-level encapsulation with C++. I've defined a class and created two objects from that class. #include <iostream> #include <ctime> #include <string> using namespace std; class timeclass { private: string date; time_t gmrawtime, rawtime; struct tm * timeinfo; char file_date[9]; void tm_init(int); public: timeclass(int); void print_date(); }; void timeclass::tm_init(int y) { timeinfo = gmtime(&rawtime); timeinfo->tm_year = y - 1900; // timeinfo->tm_year

C#: Partial Classes & Web Services: Separating form and functionality

房东的猫 提交于 2019-12-24 04:24:14
问题 I am dabbling in the world of web services and I've been making a simple web service which mimics mathematical operations. Firstly it was simple, passing in two integers and then a binary operator would be applied to these (plus, minus etc) depending on the method called. Then I decided to make things a little more complex and started passing objects around, but then I discovered that a web service only exposes the data side of the class and not the functional side. I was told that a good way

Java class containing only private members

帅比萌擦擦* 提交于 2019-12-24 00:03:38
问题 Lately I met a situation where I needed to create a custom VideoView to my android application. I needed an access to the MediaPlayer object and to add some listeners. Unfortunately (for me), all members of the VideoView class are private, so even extending the class wouldn't help me to gain access to its MediaPlayer object (or anything else), I had to make a complete duplicate of the class with my modifications. Well, although it is sound like I'm complaining for the "hard work", it is

Good design for delegating template-member functionality

自作多情 提交于 2019-12-23 19:20:05
问题 I am having trouble in finding simple and elegant design for the following scenario. Class Worker uses template class Helper to do some work. In the simple scenario it looks like this: template<typename T> class Helper { public: void Help(T data) : m_data(data) {} //NOTICE: Copy T const& Data() const { return m_data; } T m_data; } class SimpleWorker { public: SimpleWorker() : m_helper(SimpleData()) {} // non-temp used in reality void DoWork() { m_helper.help(); } Helper<SimpleData> m_helper;

What is the purpose of declaring a Class within another Class?

纵饮孤独 提交于 2019-12-23 15:06:17
问题 I come from the VBA world where options to breakdown your code into classes, namespaces, and modules is limited. Now I just landed in a world where the options are many, and I feel lost. I would like to know what is the purpose of declaring a Class within another Class? (see example below) Class FirstClass Public OnePropertyInside As String Class SecondClass Public AnotherProperty As String End Class End Class If I create a new instance of FirstClass (say myFirstClass ), SecondClass is not

Is encapsulation violated, if I use a global variable in a class member function's definition?

前提是你 提交于 2019-12-23 10:11:56
问题 I've been asked to explain what encapsulation is and I replied "bundling of data and functions that modify this data, is called encapsulation." The answer was followed by another question—"So, by your definition if I modify a global variable from a member function of a class then the encapsulation is violated." It made sense to answer YES. I am not sure whether my explanation is wrong or following question is valid and my answer to it as YES is correct. Can somebody help. 回答1: Quoting from

Object-Oriented design - how important is encapsulation when there're lots of data-fields in one class?

空扰寡人 提交于 2019-12-23 10:06:59
问题 I've a question regarding encapsulation: Is it recommended to use encapsulation when a class has lots of data-fields? Using the following class as an example: abstract public class Character { private String name; private String characterClass; private int level; private int hitDice; private int strength; private int constitution; private int dexterity; private int intelligence; private int wisdom; private int charisma; private int hp; private int currentHp; private int armorClass; private