Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Exam prep
November 14, 2009 06:58PM
I think for the exam, possibly in addition to the 2008 exam answers (other posting), maybe we can all come up with some ideas about what we might expect in this years exam. Maybe in question form, as if it was an actual exam question? I would think to also add the answer (or what we think is the answer!).
I don't want to fail this exam (as obviously not-one else does either duh!), and maybe this will just help prepare everyone a bit better.
Then we can all comment about what we think might or not be asked.

Question (3 marks)
In words (i.e. not code) explain the implementation of the Singleton Pattern
Answer
The object's constructor is declared either private or protected, and a static function (e.g. instance()) provides access to the constructor, either creating a new instance if one not already existing, or returning a pointer or reference to the current running instance if one already running.
Re: Exam prep
November 14, 2009 09:23PM
Question (2 marks)
Explain the use of the Facade Pattern
Answer
A class using the Façade pattern provides a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier and safer to use. A Façade is a class with a clear simple interface that encapsulates and hides a complicated set of classes and/or functions.
avatar Re: Exam prep
November 14, 2009 10:36PM
Here's a good question though (might come up):

What's the difference between the façade pattern and the adapter pattern?
Re: Exam prep
November 15, 2009 10:49AM
Question
Name the 3 different types of design patterns, give 2 examples of each. (6 marks)

Answer
Creational (Abstract factory, Singleton)
Structural (Facade, Composite)
Behavioral (Visitor, Observer)
Re: Exam prep
November 16, 2009 12:27PM
Fantastic Idea,

Unfortunately my knowledge is still too poor to add any useful contributions, however I am currently on the Monostate Pattern, so I ask this question -

Compare and contrast the Singleton and Monostate Pattern
Re: Exam prep
November 16, 2009 07:19PM
The singleton pattern allows one instance of an object to exist, whereas the Monostate allows multiple instances of an object to be in the same state. Remember (if I am not mistaken in this) that the state of an object is determined by the values of its data members, and in this case the object exists as many instances, but they are all exactly the same state, i.e. clones?
Re: Exam prep
November 16, 2009 07:56PM
Assuming you have the following:

Language: C++ (QT)
[singleton.h] class Singleton : public QObject { Q_OBJECT public: static Singleton *getInstance(); void setOtherParams(); // ...   private: Singleton(); static Singleton *instance; };     [singleton.cpp] #include “singleton.h” Singleton *Singleton::instance = 0   Singleton *Singleton::getInstance() //this is the singleton factory { if( instance == 0 ) { instance = new Singleton(); } return instance; }

Now in the main file, how exactly do you create an object of Singleton above, and how do you call the other functions, like setOtherParams() above. Note I haven't put the implmentation of the function, just the definition.

I actually don't know the answer here, so if someone can help me.

Thanks.
Re: Exam prep
November 16, 2009 11:24PM
A possible addendum to Shaun's first post re Singleton Vs Monostate.

Once an instance of a Singleton class has been created, any future attempts to create the same class will point to the first instance.

This is my understanding anyway

So only one instance of a Singleton with pointers for future creations and many possible instances of a monostate, but all posses the same state.

I am happy to be corrected.
avatar Re: Exam prep
November 16, 2009 11:24PM
@Shaun,
I think the following will work for main but I'm open to correction as I haven't tried it out.

Language: C++ (QT)
int main(int argc, char* argv[]) { Singleton *aRefToSingleton = Singleton::getInstance(); aRefToSingleton->setOtherParams(); }

Also wrt the Exam 2008 Post Question 7.3 my answer would be:
Yes, the user/client knows that it is dealing with a Singleton because the constructor is private and the object cannot be created by merely calling the constructor. Rather the user/client has to call a function that returns a pointer to the already instantiated Singleton object.

A lot of oop terms in the 7.3 answer... I hope I haven't abused the terminology.
Re: Exam prep
November 17, 2009 08:12AM
Thanks.
I have also updated the answer for the 2008 exam.
avatar Re: Exam prep
November 17, 2009 11:18AM
I'm not really a fan of using pointers everywhere in a program. I prefer to use references wherever possible instead. Qt makes this difficult, unfortunately.

One of the reasons I don't like pointers is that you have to worry about memory management. You have to make sure that everything that you've created with 'new' must be destroyed with 'delete'. In the example of the Singleton pattern above, there's no way to destroy the class once you've finished.

There's another way of creating Singleton classes that doesn't require pointers but has it's own set of problems.

Language: C++
[h file] class Singleton{ public: Singleton &instance();   protected: static Singleton classInstance; Singleton(); ~Singleton(); };   [cpp file] Singleton Singleton::classInstance; // automatic instance creation   Singleton::Singleton(){ // initialisation }   Singleton::~Singleton(){ // destruction }   Singleton &Singleton::instance(){ return classInstance; }

One of the main disadvantages of the Singleton pattern is that it's doesn't fit neatly into Object-oriented programming. An example of what I mean is that it's difficult to extend singletons by creating derived classes. This is because you can't create virtual static functions. This means that you'll always get the base class returned if you retrieve the instance.

A disadvantage of the variation of the implimentation that I've given is that you've got no control over the initial object creation. The instance is global (although only accessible via the class functions) but you've got no control over the order of creation. You'll be in a bit of a fix if your singleton requires interaction with other global data but the singleton gets created before it's dependent data does.
Re: Exam prep
November 17, 2009 08:46PM
..and if they ask me about this in the exam, I'll be here re-doing this module again!
avatar
Rey
Re: Exam prep
November 19, 2009 09:33AM
My guess is

1. Libraries
2. Signals and Slots. Show implementation and why is it useful
3. What pattern would be applied to this scenario. Positive this will be there smiling smiley
4. Visitor thumbs up smiley (because it's used everywhere), Observer (because Qt uses Signals and Slots), and Composite (QObject) patterns
5. Threads and processes (Like what are the differences or make this threadable)
6. Regex - Validators and/or example
7. Name an Anti-pattern (maybe)
8. Creational - Structural - Behavioural - one example each and/or define
9. XML (Don't know how much they'll ask but almost positive there will be something on it)
10. UML (Well that's what they said)
11. Something on Factory patterns. This is, what I feel, one of the "larger" patterns and maybe the most flexible in application, so it could be anything.

Again just my thoughts. Can predict anything, but if you don't know the work, you don't know the work.

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Re: Exam prep
November 19, 2009 10:10AM
Yes, sounds good, unfortunately I don't know anything about XML, apart from what the structure of the file looks like, I don't know the theory/implementation of it.
Anonymous User
Re: Exam prep
November 19, 2009 11:25AM
There's been an xml question that asks the output of some xml code and if it does output or does it fail, etc
Re: Exam prep
November 19, 2009 03:35PM
@Rev. A good list of possibilities.

I feel that because the exam will be an hour shorter (that is a whole lot of time to the previous three hour exam), that there are likely to be fewer questions than in the past for obvious time constraints. My money is on 6-8 (broad topics with sub questions), and more theoretical, so that they can get through more individual questions.
avatar
Rey
Re: Exam prep
November 20, 2009 08:44AM
We can all hope. They may just give us less marks for the same amount of work confused smiley

I really hope there's more theory, cause I've haven't done way enough practical.

I can probably implement almost all the design patterns in C++, but the Qt stuff worries me eye popping smiley

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Anonymous User
Re: Exam prep
November 20, 2009 09:46AM
Here's my singleton:
Language: C++ (QT)
class Singleton{ private: static Singleton* s; Singleton(){}; ~Singleton(){}; public: static Singleton* instance(){ if (!s) s = new Singleton; return s; } };
avatar
Rey
Re: Exam prep
November 20, 2009 09:54AM
Language: C++ (QT)
Singleton* Singleton::instance() { static Singleton* s = 0; if (s == 0) { s = new Singleton(); } return s; }

http://cartan.cas.suffolk.edu/oopdocbook/opensource/singleton.html

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Anonymous User
Re: Exam prep
November 20, 2009 10:04AM
ShaunGVW Wrote:
-------------------------------------------------------
> Yes, sounds good, unfortunately I don't know
> anything about XML, apart from what the structure
> of the file looks like, I don't know the
> theory/implementation of it.

All you need to know about xml: http://www.w3schools.com/xml/default.asp
Anonymous User
Re: Exam prep
November 20, 2009 10:06AM
Thanks Rey
Anonymous User
Re: Exam prep
November 20, 2009 11:02AM
Are signals access modifiers always "public"?
avatar
Rey
Re: Exam prep
November 20, 2009 12:47PM
Sorry Rick...my C++ vocab must be rusty but what do you mean?

Signals are public protected (Thanks Bini) (try make them private and see what happens) and slots can be private or public.

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Anonymous User
Re: Exam prep
November 20, 2009 12:53PM
Signals are protected, says so in TFM
Anonymous User
Re: Exam prep
November 20, 2009 01:07PM
Well, there's an example of it as public in TFM, Bini
Anonymous User
Re: Exam prep
November 20, 2009 01:08PM
test post. Database is giving errors!
avatar
Rey
Re: Exam prep
November 20, 2009 01:12PM
Hmmm. me too. Trying to do a search on the forums internal server error 500 or something

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
avatar
Rey
Re: Exam prep
November 20, 2009 01:18PM
@Rick

Sorry were?

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
avatar
Rey
Re: Exam prep
November 20, 2009 01:23PM
Patterns I'm learning/learnt:
+Behavioral:
Command
Iterator
Observer
Visitor
Strategy (Thanks Duncan)

+Structural:
Adapter
Composite
Facade

+Creational:
Factory Method
Abstract Factory
Singleton

I'm I missing any that were in the book and may be asked?

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Anonymous User
Re: Exam prep
November 20, 2009 01:25PM
looks good Rey. The db seems to lock up when we try other functions. I'm trying to post a quote and code and that's when it bombs
Sorry, only registered users may post in this forum.

Click here to login