What are Delegates? [duplicate] - objective-c

This question already has answers here:
How does a delegate work in objective-C?
(5 answers)
Closed 7 years ago.
I have several documents and the videos on Stanford that explain it, but I still fail to get my head around what Delegation actually is.
I'm trying to picture them in a real use so I can relate to it.
Are the similar to event hooks? I've used event hooks in some PHP frameworks.
Sometimes I need things explaining in lamans terms before I can go "ah ha, I get it".
Thanks.

In software engineering, the delegation pattern is a design pattern in object-oriented programming where an object, instead of performing one of its stated tasks, delegates that task to an associated helper object.
Read this wikipedia article in detail.

Related

Is there "more" real world example of Abstract Factory pattern? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am currently going through the design patterns of OPP. Just to give you some background. This is not my first time encountering the patterns. I've been programming for a while (decade or so) and I am pretty familiar with many programming principles, especially SOLID. I've been mostly doing web applications development, so maybe I am missing something that could've been learnt in different programming areas.
As the title suggests, I am struggling with grasping deeper the abstract factory pattern. I do understand the definition and also the "when to use the pattern" parts, but I am still missing the point. Especially when adding the Open closed principle from SOLID to the equation.
What do I mean?
The image above is taken from the Design Patterns book from GOF.
To make this post really a question of sort, there are two things that I myself can not find answer to:
When you study Open closed principle it stays that classes should stay closed for modifications. The implementation it results into is something approximating Strategy pattern. When you look at the method structure of AbstractFactory, it lists all the products it creates as separate methods. This means when we want to add new product to the family, we need to modify the AbstractFactory and create new method. Is this not a violation of Open closed principle? Maybe there is not better way to do this, is it?
Secondly, could anyone provide me with some real world example besides the ones used in the books (WidgetFactory - GOF, PizzaStore - HeadFirst)? Do you have any common implementations where you can say "Yes, this is something I usually implement with Abstract factory"? When is Abstract factory truly useful? Or am I understanding the pattern well, but it's just not that common in web development?
I hope I somehow managed to express my uncertainties regarding the pattern. In any case feel free to ask follow up questions, I'll be happy to provide more details.
Thank you in advance!
Dan
The implementation [OCP] results into is something approximating Strategy pattern.
Possibly. There are multiple ways to fulfill the OCP. Bertrand Meyer originally touted inheritance when he defined the principle.
...when we want to add new product to the family, we need to modify the AbstractFactory and create new method. Is this not a violation...
Possibly. It depends on how you implement the pattern, but the GoF book does acknowledge this problem on page 90.
Supporting new kinds of products is difficult. Extending abstract factories to
produce new kinds of Products isn't easy. That's because the AbstractFactory
interface fixes the set of products that can be created. Supporting new kinds of
products requires extending the factory interface, which involves changing
the AbstractFactory class and all of its subclasses. We discuss one solution to
this problem in the Implementation section.
The solution mentioned in the GoF book is to parameterize the AbstractFactory method, which results in its own set of problems.
...it's just not that common in web development?
No, it's not. Dependency Injection was not a common pattern when the GoF book was written, but today it has all but replaced the need for Abstract Factories. I would almost be willing to go so far as to call Abstract Factory an anti-pattern today; but I remain open-minded that there could be a problem better suited to AF than DI. I just haven't seen one yet.

What is the main purpose of inheritance in OOP? [duplicate]

This question already has answers here:
Why use inheritance at all? [closed]
(13 answers)
Closed 7 years ago.
What is main purpose of inheritance in OOP? i'm new in programming but I think maybe could be code reuse, are there more purposes or a more important purpose?
The main purpose of inheritance in Object Orientated Programming (OOP) is to give the user ability to change the behavior of the libraries, without actually changing already working and debugged code.
Changing other people's code always has a risk of introducing bugs because you may not fully understanding how the code works. In OOP, the user inherits the object and implements the behavior changes or new features with his own code, separate from the original code.
This way if there are bugs, the user needs to debug and fix only his own code, which is of course an easier task.

What is the usage of a class? [duplicate]

This question already has answers here:
VB.NET What is the purpose of a class or module?
(7 answers)
What's the point of OOP?
(45 answers)
Closed 8 years ago.
I understand how to create a class. I understand how to work with it in normal situations. However, I don't see the point of the reason. Can someone give clarification?
Well the point is to make coding more manageable. easier to add and ASSOCIATE functions, properties attributes etc than individually coding them as separate entities.
For instance you write functions to change system sound, one to increase it, other to decrease it and third to mute it. In non-OO languages they would literally be like Increasesoundfunc, Decreasesoundfunc and mutesoundfunc. while in OO they'd be like Soundclass.inreasesound, Soundclass.decreasesound ,Soundclass.mutesound . Horrible example, but you get the point.
Return to the Basics... A Class supposed to be a representation of an object from the real live, most of the time this is true, maybe its only how the computer its able to understand us.
Something its true about the classes: everything, every system, dll, framework, control, etc, etc, was made from a lot of classes.
hope it help you.... :)

How to learn Pharo [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I installed Pharo 1.4 and tried to read "Pharo by example".
Unfortunately, the book and the Pharo image were totally out of synch with each other: menus were different; classes used as examples were not there e.g; BouncingAtomsMorph class.
It is a pity. Maybe one should use a specific Pharo version to learn and another to get up to date...can anyone help?
First of all be sure to complete Prof Stef's tutorial, it gives basic knowledge. You can start the tutorial by executing
ProfStef go.
in a workspace. Just type it in the workspace, select it, right-click, Do it
There is also a Pharo collaborative book that has interesting things. And there are Pharocasts that can help you to learn something interesting.
Also you can ask questions here on Stack Overflow an tag them with pharo or smalltalk if it's more general and people will help you out.
As said by #Sharphawk, there is an image to be used with the book, available from the homepage. It's a bit old by now, but it should be in sync with the book.
Pharo simply evolves too fast for us to keep up with the book (there are still many chapters under progress), so with recent images you'll have to adapt and discover a bit by yourself. Fortunately there are a lot of other ressources where you can get help: here of course, mailing lists for the book and for Pharo itself, the #pharo-project IRC channel on irc.freenode.net, the books & screencasts pointed to by #uko, etc.
From experience, Smalltalk is much easier to learn with some exploration and mentoring
For absolute beginners, the following is a very recent practical and hands-on tutorial, covering just the basics to get you going:
http://ceronio.net/2017/07/first-steps-with-pharo-smalltalk/
As your question is a bit vague (understandably), and I do not know your background or your needs, I'll try to give a short overview over Pharo, so that you know where to look for, as you gain more experience and your needs evolve.
Language Basics
As Uko has pointed out, if you are new to Smalltalk the best way to get started
is to follow Prof Stef's tutorial. This will get you familiar with the core aspects of the language. For quick reference, you can use the Pharo Cheatsheet.
Basic Tooling
After you have completed the tutorial, you should familiarize yourself with the tools so that you can work effectively in Pharo. Vital tools, as you probably already know, are the Class Browser, the Inspector and the Debugger.
Learning from Code Examples
The Class Browser has a lot of useful features, in particular it allows you to search the system for method and class references, pointing you to concrete code examples. You can right-click on any method and then choose "Senders of..." in the context menu. Similarly, for classes, you can look for references (Analyze -> Class Refs). This will tell you how particular classes and methods are used, and more than often, will get you faster to the information you need.
Another indispensible tool is Spotter (shift-enter), which provides an easy to use interface to browse the system (for classes and examples). But you'd have to use recent Pharo version.
Ecosystem Overview
That being said, the Pharo ecosystem is quite huge and it will take you some time to get the most out of it (I have been working with Pharo for quite some time now, and there are many things I still have to learn).
Depending on your needs, Pharo has a lot to offer:
Roassal (for software & data visualization)
Glamourous Toolkit (GT) (including Spotter, the Debugger, and the Inspector).
GT allows you to customize all of its tools. For instance, you can customize the inspector very easily to have domain-specific views for your objects. Lots of built-in libraries, such as PetitParser, have customized interfaces that allow you to work more effectively with objects.
Morphic for writing GUIs. There is also Spec, a DSL built on top of morphic, which allows you to describe user-interfaces.
Monticello for version control and building packages that can be deployed to other images.
SUnit for writing testcases.
Roassal is very different from Morphic as it is tailored for rendering all sorts graphs in nice layouts (while it is possible to do that in Morphic as well, you'd have to write a lot of code). Also Roassal uses Vector Graphics, Morphic is raster-based.
If you want to write GUIs or a game, I'd stick to morphic. If you have to visualize data, use Roassal.
An excellent introduction into the core concepts of Morphic is given by Maloney (the originator of Morphic). Some class names have changed, but you'll figure it out.
There are also different ways in doing event handling in Morphic. One way is to override methods (like you are used from other object-oriented GUI frameworks), another way is to "route" events to methods. I have used both methods, and I'd pick the first one for simpler applications.
Start with a simple project
My advice would be to start with the very basics, best with a small project, for instance a game like Snake. Add things as you learn and if you are stuck, feel free to ask questions on stackoverflow. Also, there is the Pharo mailing list.
I found that the Pharo / Smalltalk community is very welcoming.
My last advice would be: Keep things simple. It's not always easy to do, but Smalltalk is a great environment to learn this principle. You'd also want to look at Kent Beck's Best Practice Patterns if you are looking for ways how to organize your code.
Have fun!
Edit: Holy thread resurrection! I just realized that the question is over 4 years old. Well, maybe this post if some help to other newcomers.

What third-party frameworks / libraries / utilities exist to aid the creation of forms with UITableView? [duplicate]

This question already has answers here:
Existing iOS form framework
(3 answers)
Closed 8 years ago.
I've spent the past few days making a nice form using a UITableView. This includes shuttling values back and forth to entities managed by Core Data (they are laid out arbitrarily which makes using NSFetchedResultsController impractical), adding nested UITableViews for choosing between multiple values, validating the data and displaying errors when values are invalid, adding support for "tabbing" between fields using the return button, and so forth.
Bravo to Cocoa Touch for bringing so much to the table, but there's still lots and lots of glue code I wrote that could be abstracted out. It would be fun to do this, but I can't believe that ~2 years into iOS development there aren't already lots of open-source projects that provide helper solutions to this.
I've looked at dozens of iOS-related open-source projects, but I haven't found anything related to this area beyond a few custom cells here and there.
Can you point me to any projects that ideally provide holistic solutions to this? I'm also interested in the "point solution" frameworks if you know of any.
Thank you.
IBAForms looks quite promising and supports binding the form to a model using KVC.